简体   繁体   English

显示存储在SharePoint文档文件夹中的HTML页面

[英]Display HTML page stored in SharePoint documents folder

I'm working on a SharePoint web part that displays a number of different reports in different divs on the page. 我正在开发一个SharePoint Web部件,该部件在页面上的不同div中显示许多不同的报告。 In one of these divs, I need to display the HTML from a page we have stored in the 'Documents' container within SharePoint. 在这些div之一中,我需要显示我们存储在SharePoint中“文档”容器中的页面的HTML。 The info in the HTML page is retrieved from several different parts of the application, and is displayed differently, so basically we're using it as the source data. HTML页面中的信息是从应用程序的多个不同部分检索的,并且以不同的方式显示,因此基本上我们将其用作源数据。 I'm trying to figure out how to access the page from within the app and hopefully store the link to the file as a configurable setting so I can set it up for our dev/test/prod environments. 我试图弄清楚如何从应用程序内访问页面,并希望将指向文件的链接存储为可配置的设置,以便为我们的开发/测试/产品环境进行设置。

I've loaded the HTML file into the 'Documents' folder, and if I browse to it manually it displays fine but if I use the following: 我已将HTML文件加载到“文档”文件夹中,如果我手动浏览到该文件,它会正常显示,但是如果使用以下命令:

SPSecurity.RunWithElevatedPrivileges(delegate
{
    using (System.Net.WebClient client = new System.Net.WebClient())
    {
    string htmlCode = client.DownloadString(url);
    }
}

I get a 403 error and in the response header the message, "Before opening files from this location you must first browse to the website and select the option to login automatically". 我收到403错误,并在响应标题中显示消息:“在从该位置打开文件之前,您必须先浏览到网站并选择自动登录的选项”。

I thought the RunWithElevatedPriveleges would pass the credentials through but I'm pretty new to SharePoint. 我以为RunWithElevatedPriveleges可以通过凭据,但是我对SharePoint很陌生。 Not sure if I'm using the right approach, any help is appreciated. 不知道我是否使用了正确的方法,我们将为您提供帮助。

Put the pages into a standard document library, then use the page viewer web part. 将页面放入标准文档库中,然后使用页面查看器Web部件。 The site asset library is used for other customization purposes. 站点资产库用于其他自定义目的。 You don't even need SharePoint Designer. 您甚至不需要SharePoint Designer。 Page viewer should be set as a "Web Page" because the web page viewer becomes essentially an IFRAME. 页面查看器应设置为“网页”,因为该网页查看器实际上已成为IFRAME。

If still trouble... it may be a setting at the Web Application level thats causing issues with non-Microsoft files 如果仍然有问题...这可能是Web应用程序级别的设置,导致非Microsoft文件出现问题

Go to Central Admin > Manage Web Applications. 转到中央管理>管理Web应用程序。 I then chose my Web Application and clicked on the "General Settings" button. 然后,选择我的Web应用程序,然后单击“常规设置”按钮。 I then changed the Browser File Handling from "Strict" to "Permissive" and that fixed my issue. 然后,我将浏览器文件处理从“严格”更改为“允许”,从而解决了我的问题。 I've included an attachment of the setting so you can read the text associated with it. 我附带了该设置的附件,因此您可以阅读与此设置相关的文本。

在此处输入图片说明

Figured it out. 弄清楚了。 There were a number of permissions problems but once those were sorted this code worked: 存在许多权限问题,但对这些权限问题进行排序后,此代码就可以工作:

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.

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