讲解如何sharepoint如何构造html静态发布,包括本地读写,页面库html读写等等问题。
sharepoint静态html新闻发布系统之静态发布内容,晚上更新,请耐心等待。
moss静态html新闻发布系统相关代码:
moss静态html新闻发布系统相关代码:
1、获取aspx的源代码方法
/**//// <summary>
/// 通过WebClient下载相关页面的html代码
/// </summary>
/// <param name="Url"></param>
/// <returns></returns>
public string getUrltoHtml(string Url)
{
System.Net.WebClient wc = new System.Net.WebClient();
byte[] bs = wc.DownloadData(Url);
//string result = Encoding.UTF8.GetString(bs);
string result = System.Text.Encoding.UTF8.GetString(bs);
return result;
}
2、修正生成html文件到页面库一个错误的bug,关于签入迁出bug
/**//// <summary>
/// 通过WebClient下载相关页面的html代码
/// </summary>
/// <param name="Url"></param>
/// <returns></returns>
public string getUrltoHtml(string Url)
{
System.Net.WebClient wc = new System.Net.WebClient();
byte[] bs = wc.DownloadData(Url);
//string result = Encoding.UTF8.GetString(bs);
string result = System.Text.Encoding.UTF8.GetString(bs);
return result;
}
2、修正生成html文件到页面库一个错误的bug,关于签入迁出bug
moss静态发布主方法
/**//// <summary>
/// 重写静态页面html文件到页面库
/// </summary>
/// <param name="htmlPageName"></param>
/// <param name="htmlfile"></param>
public void RewriteHtmlPage(string htmlPageName, string htmlfile)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite mysite = new SPSite(localSiteUrl))
{
using (SPWeb myweb = mysite.RootWeb)
{
mysite.AllowUnsafeUpdates = true;
myweb.AllowUnsafeUpdates = true;
SPDocumentLibrary doclib = myweb.Lists["页面"] as SPDocumentLibrary;
string documentName = htmlPageName;
string libraryRelativePath = doclib.RootFolder.ServerRelativeUrl;
string libraryPath = mysite.MakeFullUrl(libraryRelativePath);
string documentPath = libraryPath + "/" + documentName;
SPFile file = myweb.GetFile(documentPath);
//if ((file != null) && (file.CheckOutStatus != SPFile.SPCheckOutStatus.None))
//{
try
{
file.CheckOut();
}
catch
{
}
//}
if (file.Exists != true)
{
byte[] content = System.Text.Encoding.UTF8.GetBytes(htmlfile);
myweb.Files.Add(documentPath, content);
//文件迁入
if (file != null)
{
file.CheckIn("已签入", SPCheckinType.MajorCheckIn);
//file.Publish("已发布");
file.Update();
}
}
else
{
//if ((file != null) && (file.CheckOutStatus != SPFile.SPCheckOutStatus.None))
//{
try
{
file.CheckOut();
}
catch
{
}
//}
//获取发布首页的html源代码
byte[] content = System.Text.Encoding.UTF8.GetBytes(htmlfile);
file.SaveBinary(content);
if (file != null)
{
//file.CheckIn("已迁入");
file.CheckIn("已签入", SPCheckinType.MajorCheckIn);
//file.Publish("已发布");
file.Update();
}
}
}
}
});
}
/**//// <summary>
/// 重写静态页面html文件到页面库
/// </summary>
/// <param name="htmlPageName"></param>
/// <param name="htmlfile"></param>
public void RewriteHtmlPage(string htmlPageName, string htmlfile)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite mysite = new SPSite(localSiteUrl))
{
using (SPWeb myweb = mysite.RootWeb)
{
mysite.AllowUnsafeUpdates = true;
myweb.AllowUnsafeUpdates = true;
SPDocumentLibrary doclib = myweb.Lists["页面"] as SPDocumentLibrary;
string documentName = htmlPageName;
string libraryRelativePath = doclib.RootFolder.ServerRelativeUrl;
string libraryPath = mysite.MakeFullUrl(libraryRelativePath);
string documentPath = libraryPath + "/" + documentName;
SPFile file = myweb.GetFile(documentPath);
//if ((file != null) && (file.CheckOutStatus != SPFile.SPCheckOutStatus.None))
//{
try
{
file.CheckOut();
}
catch
{
}
//}
if (file.Exists != true)
{
byte[] content = System.Text.Encoding.UTF8.GetBytes(htmlfile);
myweb.Files.Add(documentPath, content);
//文件迁入
if (file != null)
{
file.CheckIn("已签入", SPCheckinType.MajorCheckIn);
//file.Publish("已发布");
file.Update();
}
}
else
{
//if ((file != null) && (file.CheckOutStatus != SPFile.SPCheckOutStatus.None))
//{
try
{
file.CheckOut();
}
catch
{
}
//}
//获取发布首页的html源代码
byte[] content = System.Text.Encoding.UTF8.GetBytes(htmlfile);
file.SaveBinary(content);
if (file != null)
{
//file.CheckIn("已迁入");
file.CheckIn("已签入", SPCheckinType.MajorCheckIn);
//file.Publish("已发布");
file.Update();
}
}
}
}
});
}
最终预览效果如下:www.aepb.gov.cn