}
完整的代码如下:
using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using System.IO;
namespace MyWebPart
{
[Guid("9a7ee2e6-ebff-4594-a3e3-d59aceae4e45")]
public class MyWebPart : System.Web.UI.WebControls.WebParts.WebPart
{
public MyWebPart()
{
this.ExportMode = WebPartExportMode.All;
}
protected override void Render(HtmlTextWriter writer)
{
this.EnsureChildControls();
this._innerControl.RenderControl(writer);
}
private System.Web.UI.Control _innerControl;
protected override void CreateChildControls()
{
using (StreamReader reader = new StreamReader(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("SampleWebPart.WebUserControl1.ascx")))
{
String resourceContent = reader.ReadToEnd();
using (StreamWriter writer = new StreamWriter(this.Page.Server.MapPath("/bin/MyWebUserControl.ascx"), false))
{
writer.Write(resourceContent);
}
}
this._innerControl = this.Page.LoadControl("/bin/MyWebUserControl.ascx");
this.Controls.Add(this._innerControl);
}
}
}
注意: