SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My problem is simple. From an aspx page, I need to open in a new window a document stored in Sharepoint. To access the document in SharePoint I need to provide credentials. To open the document in a new window, I need to use javascript. => how to link the two ? here is the code :

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

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


    // 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 = "'" + myUrltotheDocument + "','','width=800,height=800,resizable=yes,scrollbars=yes');";
    ScriptManager.RegisterStartupScript(myPanel, myPanel.GetType(), "ShowInfo", strScript, true);

Thank you for your help.

share|improve this question
May be SharePoint is not the right place to store and handle documents, if we cannot retrieve a document knowing its path and the credentials ! I think I should better use an Oracle database with blob fields... – Mister B. Oct 16 '13 at 22:34

Finally, the only way I found to open the document in a new window from a .aspx page, is to download the document in a folder on the server, and then, to open a window in javascript with a link to the downloaded document.

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 = "'" + strLocalName + "','','width=800,height=800,resizable=yes,scrollbars=yes');";
ScriptManager.RegisterStartupScript(myPanel, myPanel.GetType(), "ShowInfo", strScript, true);

I do not consider this as a "nice solution", but it does the job... If someone has a better one, please tell me.

Thank you for the ones who took time to answer.

share|improve this answer

If the document is saved in a sharepoint library you can change the library settings so that the document, when clicked, is not downloaded but opened in a new browser window. Have you tried this?

share|improve this answer
This is an interesting link. In my case, the user does not click directly on the link in SharePoint. The document is accessed by a .Net application, with .aspx pages. – Mister B. Oct 17 '13 at 21:58
Check if you have installed office web apps on the sharepoint server. – Skaft Oct 18 '13 at 9:28
Office web apps is not installed on the sharepoint server. We will install it. This, may be, can solve the problem for Office documents, but not for .pdf, jpg,... – Mister B. Oct 21 '13 at 21:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.