C#,vb.net,MVC,Jquery,javascript,jscript,vbscript,html,vb,sharepoint,COM,WPF,WCF,Wwf,Asp,Asp.net,questions & answers,

Latest in Sports

Friday, January 24, 2014

Error When Downloading a File from secured Share Point Server from MVC 4 Application

I am developing MVC 4 Razor Application.

I  Placed  a “ Action Link “ Download Button which downloads file from HTTPS Sharepoint Server.

Error : Am getting 403 Forbidden Error in Web Request


Code Snippet :


string url = "https://xyz.com/files/sample.docx"; --à SharePoint Server File URL

            WebRequest request = WebRequest.Create(new Uri(url, UriKind.Absolute));

            request.Credentials = new NetworkCredential("XYZ", "XYZ");

            WebResponse response = request.GetResponse();

            Stream fs = response.GetResponseStream() as Stream;

            byte[] buffer = new byte[16 * 1024];

            using (MemoryStream ms = new MemoryStream()) {

                fs.CopyTo(ms);

              buffer=  ms.ToArray();

            }

            return File(buffer, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", fileName);


I got 403 Forbidden Exception in Highlighted Area.

No comments:

Post a Comment