在新窗口中打开存储在SharePoint中的文档

时间:2013-10-14 23:50:11

标签: c# javascript asp.net sharepoint

我的问题很简单。从aspx页面,我需要在新窗口中打开存储在Sharepoint中的文档 要在SharePoint中访问文档,我需要提供凭据 要在新窗口中打开文档,我需要使用javascript =>如何链接这两个? 这是代码:

        ClientContext ctx = new ClientContext(strServerUrl);
        Web currentWeb = ctx.Web;

        ctx.Load(currentWeb);
        ctx.Credentials = new System.Net.NetworkCredential("Login", "Password", "Domain");

        ctx.ExecuteQuery();

        // Here I have access to SharePoint. 
        // I can download the document, but I just want to display it in a new window

        // something is missing here

        string strScript;
        strScript = "window.open('" + myUrltotheDocument + "','','width=800,height=800,resizable=yes,scrollbars=yes');";
        ScriptManager.RegisterStartupScript(myPanel, myPanel.GetType(), "ShowInfo", strScript, true);

感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

尝试以下方法:

window.open(myUrltotheDocument",_blank","toolbar=no,menubar=0,status=0,copyhistory=0,scrollbars=yes,resizable=1,location=0,Width=800,Height=800") ;

答案 1 :(得分:0)

最后,我发现从.aspx页面在新窗口中打开文档的唯一方法是将文档下载到服务器上的文件夹中,然后在javascript中打开一个窗口,其中包含指向下载文件。

Uri uriVar = new Uri(strDocUrl);

int intDirectoryIndex = uriVar.LocalPath.LastIndexOf("/");
string strFileName = uriVar.LocalPath.Substring(intDirectoryIndex + 1);

System.Net.WebClient wcVar = new System.Net.WebClient();
wcVar.Credentials = new System.Net.NetworkCredential("Login", "Pwd", "Domain");
string strPath = HttpContext.Current.Server.MapPath("~/FileUpload/");
wcVar.DownloadFile(strDocUrl, strPath+strFileName);
string strLocalName = "FileUpload/" + strFileName;

string strScript;
strScript = "window.open('" + strLocalName + "','','width=800,height=800,resizable=yes,scrollbars=yes');";
ScriptManager.RegisterStartupScript(myPanel, myPanel.GetType(), "ShowInfo", strScript, true);

我不认为这是一个“很好的解决方案”,但它可以胜任......如果有人有更好的解决方案,请告诉我。