Last post Jul 25, 2018 09:01 AM by PatriceSc
Jul 24, 2018 07:42 PM|apidude|LINK
I am hosting a web api on IIS 10.0, I created a method that will retrieve a pdf from a folder. Works well locally in VS and works when the files are on the server, but when I am trying to retrieve the files from a network file system I am getting and error
and in IIS log it is 404 0 0 15. Now i Checked that 15 is "drive not found" error. I think I need to give permission to some user on IIS to this folder. I am unable to determine which user needs access to the network folder. Any help appreciated.
Jul 24, 2018 07:52 PM|PatriceSc|LINK
It is done with code? A server side runtime error should be http 500. If done using IIS configuration could it be that you mapped a virtual folder to a drive letter. Use UNC path instead (it works if allowed while drive letters are configured for each user
Jul 24, 2018 09:44 PM|apidude|LINK
Thanks for your response below is my code
the fullpdfpath in the program is \\server\all invoices\ in web.config file. Its failing --if (!File.Exists(fullpdfpath)). I do not know what I am doing wrong.
--code starts here-------------------------------------
string fileName = invoiceName + ".pdf";
string filepath = ConfigurationManager.AppSettings["InvoicePath"].ToString();
string fullpdfpath = @filepath + fileName;
return Request.CreateErrorResponse(HttpStatusCode.NotFound, fullpdfpath + "File Not Found");
//throw new HttpResponseException(HttpStatusCode.NotFound);
//Copy the source file stream to MemoryStream and close the file stream
MemoryStream responseStream = new MemoryStream();
Stream fileStream = File.Open(fullpdfpath, FileMode.Open);
responseStream.Position = 0;
HttpResponseMessage response = new HttpResponseMessage();
response.StatusCode = HttpStatusCode.OK;
//Write the memory stream to HttpResponseMessage content
response.Content = new StreamContent(responseStream);
string contentDisposition = string.Concat("attachment; filename=", fileName);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
Jul 25, 2018 08:49 AM|Brando ZWZ|LINK
According to your description, I think you may not use the right file path.
So the the web application couldn't locate the right path from the server.
Could you please tell me is the pdf file folder inside the web application??
If the pdf folder is inside the web application, I suggest you could use server.mappath to access that path.
Jul 25, 2018 09:01 AM|PatriceSc|LINK
Ok. I better understand why you have a 404.
Double check fullpdfpath is correct and for now I would comment the test to see which exception happens when I actually try to read the file. The account under which your web app runs needs to have access (but it's likyl best to see first what actually happens
when trying to read this file).