2013-10-14 68 views
0

我的問題很簡單。從aspx頁面,我需要在新窗口中打開存儲在Sharepoint中的文檔。
要訪問SharePoint中的文檔,我需要提供憑據。
要在新窗口中打開文檔,我需要使用javascript。
=>如何鏈接兩個? 這裏是代碼:在新窗口中打開存儲在SharePoint中的文檔

 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); 

謝謝你的幫助。

回答

0

嘗試以下操作:

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

謝謝你的回答。這是在新窗口中打開文檔的說明...但缺少憑證。在本地環境中,系統將提示輸入登錄名/密碼。部署在服務器上時,會導致訪問錯誤。 –

+0

嘗試在加載網頁前傳遞憑證。 –

+0

我試過了:系統提示我輸入登錄名/密碼......好像它不考慮憑證。 –

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); 

我不認爲這是一個「很好的解決方案」,但它的工作......如果有人有一個更好的,請告訴我。