在新窗口中打开存储在 SharePoint 中的文档
本文关键字:文档 SharePoint 存储 在新窗口中打开 | 更新日期: 2023-09-27 18:35:16
我的问题很简单。在 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);
谢谢你的帮助。
尝试以下操作:
window.open(myUrltotheDocument",_blank","toolbar=no,menubar=0,status=0,copyhistory=0,scrollbars=yes,resizable=1,location=0,Width=800,Height=800") ;
最后,我发现从.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);
我不认为这是一个"不错的解决方案",但它可以完成这项工作......如果有人有更好的,请告诉我。