简体   繁体   English

Sharepoint自定义Web部件

[英]Sharepoint custom Web Part

I've a got a code snippet below modified from http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webpartpages.webpart.aspx : 我从http://msdn.microsoft.com/zh-cn/library/microsoft.sharepoint.webpartpages.webpart.aspx修改了以下代码段:

public class WebPartBla : Microsoft.SharePoint.WebPartPages.WebPart
{
    private ArrayList someList;

    protected override void CreateChildControls()
    {
        someList = new ArrayList();

        SPWeb myWeb = SPControl.GetContextWeb(this.Context);
        foreach(SPList list in myWeb.Lists)
        {
            if (list.BaseTemplate == SPListTemplateType.Tasks)
            {
                someList(list.Description);
            }
        }
    }

    /// <summary>
    /// Render this Web Part to the output parameter specified.
    /// </summary>
    /// <param name="output"> The HTML writer to write out to </param>
    protected override void RenderWebPart(HtmlTextWriter output)
    {
        string strHTML = "";
        for (int i = 0; i < someList.Count; i++)
        {
            strHTML = strHTML + "The task " + someList.Description + "<BR><BR>";
        }
        output.Write(strHTML);
    }
}

Could anyone please help me with 谁能帮我

  1. how to use this code as SharePoint Web Part? 如何将此代码用作SharePoint Web部件?
  2. how to deploy this to the sharepoint as web part? 如何将其作为Web部件部署到共享点?
  3. how does the RenderWebPart method above gets used? 上面的RenderWebPart方法如何使用?

Basically you need visual studio and SharePoint on the same machine to do any development. 基本上,您需要在同一台计算机上使用Visual Studio和SharePoint来进行任何开发。

Create an empty sharepoint project then add a webpart to the project. 创建一个空的SharePoint项目,然后将Webpart添加到项目中。 Put the code you have there into the webpart code file and build the solution (you will need to specify the URL of your local SP to do this). 将您那里的代码放入Webpart代码文件中并构建解决方案(您需要指定本地SP的URL才能执行此操作)。 You can then deploy via the right click menu. 然后,您可以通过右键单击菜单进行部署。 An additional component of this build is a WSP file which you can take and deploy to other sharepoint environments. 此构建的另一个组件是WSP文件,您可以将其提取并部署到其他共享点环境。

THe renderWebPart menthod here allows you to directly write HTML for the webpart in code. 此处的renderWebPart方法允许您直接在代码中为Webpart编写HTML。 Another option here is to use a visual web part. 这里的另一个选择是使用可视化Web部件。

heres a good tutorial (with pictures) showing how to create a webpart http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2010/02/15/intro-to-sharepoint-2010-development-how-to-build-and-deploy-a-web-part.aspx 这是一个很好的教程(带有图片),显示了如何创建Webpart http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2010/02/15/intro-to-sharepoint-2010-development-how-to-建立并部署一个Web部件.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM