[英]Display HTML page stored in SharePoint documents folder
我正在開發一個SharePoint Web部件,該部件在頁面上的不同div中顯示許多不同的報告。 在這些div之一中,我需要顯示我們存儲在SharePoint中“文檔”容器中的頁面的HTML。 HTML頁面中的信息是從應用程序的多個不同部分檢索的,並且以不同的方式顯示,因此基本上我們將其用作源數據。 我試圖弄清楚如何從應用程序內訪問頁面,並希望將指向文件的鏈接存儲為可配置的設置,以便為我們的開發/測試/產品環境進行設置。
我已將HTML文件加載到“文檔”文件夾中,如果我手動瀏覽到該文件,它會正常顯示,但是如果使用以下命令:
SPSecurity.RunWithElevatedPrivileges(delegate
{
using (System.Net.WebClient client = new System.Net.WebClient())
{
string htmlCode = client.DownloadString(url);
}
}
我收到403錯誤,並在響應標題中顯示消息:“在從該位置打開文件之前,您必須先瀏覽到網站並選擇自動登錄的選項”。
我以為RunWithElevatedPriveleges可以通過憑據,但是我對SharePoint很陌生。 不知道我是否使用了正確的方法,我們將為您提供幫助。
弄清楚了。 存在許多權限問題,但對這些權限問題進行排序后,此代碼就可以工作:
using (SPSite site = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb web = site.OpenWeb())
{
SPFolder folder = web.GetFolder("MainFolder/Lists/MainFolderDocs");
if (folder.Exists)
{
SPFile file = web.GetFile("/MainFolder/Lists/MainFolderDocs/Mainlist.html");
if (file.Exists)
{
using (System.IO.StreamReader reader = new System.IO.StreamReader(file.OpenBinaryStream()))
{
string htmlCode = reader.ReadToEnd();
lChecklist.Text = htmlCode;
}
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.