0

I am trying copy a file from a network share (drive letter\folder) to a SharePoint document library using asp.net (C#) when I run the code locally and select a drive letter to copy from everything works fine, but when I publish it to IIS I get an error - Could not find a part of the path 'L:\Test\Test.Doc'. I am guessing this is because the drive mapping doesn't exist from IIS.

The code to get the file is:

if (FileUpload1.HasFile)
{
    string spSite = System.Configuration.ConfigurationManager.AppSettings["SharePointSite"];
    string RelativePath = System.Configuration.ConfigurationManager.AppSettings["DocumentLibraryRelativePath"];
    SharePointIntegration sp = new SharePointIntegration();
    string fileExtension = Path.GetExtension(FileUpload1.PostedFile.FileName);
    string fileName = Path.GetFileNameWithoutExtension(FileUpload1.PostedFile.FileName);
    string filePath = Path.GetDirectoryName(FileUpload1.PostedFile.FileName) + "\\" + fileName + fileExtension;
    sp.UploadDocument(spSite, RelativePath, "Documents", filePath, fileName, recordID.ToString(), (string)HttpContext.Current.Session["UserName"], fileExtension);
    GetAttachments();
}

I am using the SaveBinaryDirect method to save the file in SharePoint - sp.UploadDocument(spSite, RelativePath, .......).

What do I need to change to get the file when it is running on IIS?

rene
  • 41,474
  • 78
  • 114
  • 152
  • Instead of relying on a mapped drive letter see if you can use an [UNC path instead](http://stackoverflow.com/questions/21482825/find-unc-path-of-a-network-drive). If that network drive needs permissions make sure your sharepoint site is either running under an identity that has those permissions or change to such an identity before you access that network location. – rene Jul 02 '16 at 09:02
  • I thought of using the UNC path but our structure is Test (\\server\files) (L:) and Test1 (\\server\files) (S:) so the UNC path would be \\server\files\Test and Test1 respectively but we could have any number of these. If I browse to \\server\files I get a list of shortcuts including Test, Test1, etc. – user6540880 Jul 02 '16 at 09:12
  • Finally sorted it by converting the drive mapping to the UNC path: http://stackoverflow.com/questions/2067075/how-do-i-determine-a-mapped-drives-actual-path/9795595#9795595 – user6540880 Jul 02 '16 at 12:45

0 Answers0