0

I am working a application which api server , db server and web server is diffent . We create a server to store file and create virtual directory to access all files . But my problem is how to store file this location . my network location is \10.0.0.51\CB-Clients how can i store file in this location. my code is

string _path =Path.Combine("\\10.0.0.51\CB-Clients\", "abc.png");
 FileStream newFile = new FileStream(_path, FileMode.Create);
newFile.Write(userWiseDocumentStorage.DocImageByte, 0, userWiseDocumentStorage.DocImageByte.Length);
newFile.Close();

but the problem is file is not uploading this location

tapos ghosh
  • 2,114
  • 23
  • 37
  • if file server is different IIS server, firstly you can access on file server using trought credentials. https://stackoverflow.com/questions/263518/uploading-files-to-file-server-using-webclient-class – Hüseyin Burak Karadag Feb 17 '18 at 13:48

1 Answers1

0

Follow these steps and try.... 1.Add the Location in WebConfig File inside AppSettings like

  <appSettings>
        <add key="DocumentationLocation" value="D:\CB-Clients" />
  </appSettings>

2.Then try this Code in Controller Action eg:

     public ActionResult FileSave(HttpPostedFileBase file)
                {

                    string _FileName = null;
                    string _path = null;                   
                    _FileName = Path.GetFileName(file.FileName);
                    string ext = Path.GetExtension(_FileName);
                    string file1 = _FileName.Replace(" ", "");

                    if (ext.ToLower() == ".pdf" || ext.ToLower() == ".doc" || ext.ToLower() == ".jpg" || ext.ToLower() == ".docx" || ext.ToLower() == ".xls" || ext.ToLower() == ".xlsx" || ext.ToLower() == ".jpeg" || ext.ToLower() == ".png")
                    {

                        string location = (System.Configuration.ConfigurationSettings.AppSettings["DocumentationLocation"]);
                        _path = Path.Combine(location, file1);
                        if (System.IO.File.Exists(_path))
                        {
                            System.IO.File.Delete(_path);
                            file.SaveAs(_path);
                        }
                        else
                        {
                            file.SaveAs(_path);
                        }
                    }
                    return View();

                }
AnuPrasad
  • 56
  • 6