0

I have some files that I need to upload to a shared folder on a remote file server, for example, to:

\\myServer\my\path

Only specific users are allowed to access to this shared folder. Files upload is done through user's browser via this ASP.NET MVC app and using a specific user and password which has permissions (total control) to access the shared folder in order to read/write/modify content.

I am using NET 4.5 and Visual Studio 2013.

How can I achieve this?

I have heard about using HttpPostedFileBase and then invoking SaveAs method but I do not know how to do it.

Willy
  • 9,848
  • 22
  • 141
  • 284
  • you want to upload the files to the server where the MVC app is hosted, or to another server? It's not clear. If the latter, what protocols does this other server allow? – ADyson Apr 27 '20 at 21:25
  • @ADyson to another server, not the same where MVC app is hosted. – Willy Apr 27 '20 at 21:51
  • Ok. So...how does this server allow you to send files to it? HTTP maybe? Or FTP perhaps? Or some other protocol? Or is `\myServer\my\path` supposed to be a UNC fileshare path (in which case I'd expect it to start with `\\ ` e.g. `\\servername\sharedfoldername`)? And is the file you're sending one which is being uploaded from the user's browser via the MVC app, or does it come from somewhere else? Again it's not really clear what the whole situation is. This information is necessary otherwise no-one can suggest any kind of solution, or even a basic approach. – ADyson Apr 27 '20 at 22:05
  • @ADyson it's a UNC fileshare path, sorry, I have corrected in the post for \\myServer\my\path. The file is being uploaded from the user's browser via the MVC app. – Willy Apr 29 '20 at 18:33
  • @ADyson my remote server has a shared folder on which I am trying to upload files through ASP.NET MVC app. I also have updated my post and its title. Is it clear for you now? – Willy Apr 29 '20 at 19:02
  • ok so as long as your app has permissions to write to the fileshare (and the share is accessible from the server where MVC is running), you can just save the file in the normal way, same as if you saved it to the C drive of the server. – ADyson Apr 29 '20 at 19:02
  • @ADyson Ok but how I specifify from my ASP.NET MVC app the specific user (which has the permissions) to use for doing the file upload to the fileshare? – Willy Apr 29 '20 at 19:04
  • It will automatically use the account that the whole MVC application runs as. i.e. the account under which the relevant IIS application pool (the one that the IIS website under which the MVC site is configured to use) is set to run with. So you need to ensure the application pool's user account has the necessary permissions. – ADyson Apr 29 '20 at 19:05
  • If you can't do that for some reason, you could try and resort to using impersonation, as per the suggestions here: https://stackoverflow.com/questions/125341/how-do-you-do-impersonation-in-net – ADyson Apr 29 '20 at 19:09

0 Answers0