Asked by:
Network file access

Question
-
User1408931231 posted
I am working with the document viewer control. I cannot seem to set the file path to a folder on the network. (ie..\\sharename\folder\file or even its mapped drive x:\folder\file). It works just fine when I put the files in the project and run it.
Any ideas?
Monday, February 11, 2019 5:23 PM
All replies
-
User753101303 posted
Hi,
Always start by telling what happens.
My guess is that you have a permission error ? The account under which your web app runs needs to have access to \\server\sharename\folder\file. If using "Application pool identity", it will be seen as DOMAIN\MACHINENAME$ when accessing a network resource: https://docs.microsoft.com/en-us/iis/manage/configuring-security/application-pool-identities#accessing-the-network
Never use a drive letter (it needs to be configured as part of the user profile) while https://en.wikipedia.org/wiki/Path_(computing)#Uniform_Naming_Convention just works if allowed.
BTW not sure which "Document viewer control" you are talking about. It could be also some something related to this control (once again always tell which error message so that we don't have first to guess which error you have on your side before even suggesting a fix).
Monday, February 11, 2019 5:41 PM -
User1408931231 posted
I am using this control:
https://github.com/HajbokRobert/WebFormsDocumentViewer
When I set the path to something like this:
string file = @"\\blah\blah\blah\blah.docx";
docViewer.FilePath = file;I do not get an error...but the the control renders on the page and says "Cannot display document viewer"
However, putting the documents in the project folder and set it like this:
docViewer.FilePath = "~/Files/blah.docx";
It works just fine. In the end I want a folder on the network that we can display these files in a browser.
Monday, February 11, 2019 7:38 PM -
User753101303 posted
It uses Server.MapPath(FilePath) which is likely what fails. it would need to be updated to check if this is a virtual path or not maybe.
Also catching exceptions to show the control can't be rendered is IMO a bad idea. I would also change this so that exceptions can be handled by the caller. Finally it requires to install Microsoft Office on the server which is not recommended.
Edit: I confirm that Server.MapPath(@"\\server\name") gives c:\siteroot\server\name so :more likely it can't load the file and the control fails with its generic error message. i would drop the call to Server.MapParth and would let the consumer to provide a physical path (possibly calling Server.MapPath himself if needed).
Monday, February 11, 2019 9:17 PM -
User1408931231 posted
Would you suggest another control? I would happily try something else.
Monday, February 11, 2019 9:20 PM -
User753101303 posted
Never tried yet but I noticed once that OneDrive allows to get a file using another format doing a conversion on the fly. So if acceptable if could be likely used as an entry level conversion service : https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_get_content_format?view=odsp-graph-online
You could give this a try with the biggest file you have to process and see if the UI allows to export that to PDF and see if good enough before doing that programmatically.
Monday, February 11, 2019 9:49 PM