0

We have a cloud based application, there is a facility called image upload where user can select an image file from his local drive and save that file to a shared folder which is not in user's network. The code which I have written works for shared folder in network but outside the network it fails. Currently I am passing path which has IP address of shared folder's computer and shared folder name attached to IP address. I think I need to pass username and password also with IP address. What I have done is

string FileName ="Image1.jpg";      
string Root = @"" + "IPAddress\\SharedFolderName" + '\\' + CustID;  
 if (!Directory.Exists(Root))    
               {    
                   Directory.CreateDirectory(Root);    
               }    
string filePath = Root + "\\" + FileName;  
File.WriteAllBytes(filePath, Convert.FromBase64String(image));    

Here "image" is file content which I want to save in shared folder.

This code is working for shared folder in network. But to access folder in other network I think I have to pass username and password. How to do that in c#? Any help would be appreciated. Thank you.

dip
  • 63
  • 1
  • 8
  • Does this answer your question? [How to provide user name and password when connecting to a network share](https://stackoverflow.com/questions/295538/how-to-provide-user-name-and-password-when-connecting-to-a-network-share) – VietDD Sep 30 '20 at 13:20
  • You can change properties of the shared folder (read/write privileges) to allow more users access. I usually start debugging using a window explorer and putting into the URL \\IPAddress. You need to determine if the issue is with the folder(s) or file and the explorer will help determine the root cause. Once you get permissions correct in the explorer the code should work in c#. – jdweng Sep 30 '20 at 13:40
  • @jdweng When I try to access using windows explorer (\\IPAddress) and I am not able to access(when that computer is not in network). But if I connect that computer in my network then using \\IPAddress I am able to access shared folder. What may be the problem? Is it firewall or something. – dip Oct 01 '20 at 11:32
  • Three things 1) Permission 2) Route 3) Firewall. I would start by using from cmd.exe >Ping IP (or computer name). Try both sometimes one work and not the other. Ping will work regardless of permissions. The PC mask may be wrong so you can check mask from cmd.exe>IPConfig/all. A PC should be configured with a default interface with mask of 0.0.0.0 so nothing gets blocked. The mask could stop messages from being sent. – jdweng Oct 01 '20 at 11:50
  • @jdweng when I try to Ping IP it says request time out. – dip Oct 01 '20 at 12:01
  • Then there is no route. Routing is is either done by getting route from a DNS server or by IP address and masks (or both). The DNS acts like a Firewall. – jdweng Oct 01 '20 at 12:07

0 Answers0