6 Replies - 22988 Views - Last Post: 25 June 2010 - 07:31 AM Rate Topic: -----

#1 Guest_Tripti*


Reputation:

The filename, directory name, or volume label syntax is incorrect.

Posted 23 June 2010 - 02:37 PM

I have report files on a remote file server (c-n-one\Reports\pdf\). I have to write c# code to download pdf file from a file server to save locally on client machine.

On my web.config I created a key as follows:

<add key ="PDFFileServer" value="\\c-n-one\Reports\pdf\"/>


The code in my download function is as follows:

protected void SaveReportsLocally(String CaseNosString)
    {
        string[] CaseNos = CaseNosString.Split(' ');
        foreach (string casenum in CaseNos)
        {
            if (casenum != "Saving:" && casenum.Trim() != "")
            {
                string[] sp_params = {casenum};

                SqlDataReader dr = csiDelegate.DataReaderProcedure("DocumentGetByCaseNo", sp_params);
                while (dr.Read())
                {
                    string DocName = dr["DocumentName"].ToString();
                    //string LocalFileName = _LocalSavePath + DocName;
                    WebClient webClient = new WebClient();
                    webClient.DownloadFile(_PDFfilesRootPath, @DocName);
                }
                dr.Close();
            }
        }
    }



Values shown in debugger:
_PDFfilesRootPath = "\\\\c-n-one\\Reports\\pdf\\"

DocName = "140020_FG10-004710_1_128.pdf"


I am getting error on line : webClient.DownloadFile(_PDFfilesRootPath, @DocName);

Error:
The filename, directory name, or volume label syntax is incorrect.

Stack Trace:

[IOException: The filename, directory name, or volume label syntax is incorrect.
]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +7717304
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) +1162
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) +61
System.Net.FileWebStream..ctor(FileWebRequest request, String path, FileMode mode, FileAccess access, FileShare sharing, Int32 length, Boolean async) +65
System.Net.FileWebResponse..ctor(FileWebRequest request, Uri uri, FileAccess access, Boolean asyncHint) +94

[WebException: The filename, directory name, or volume label syntax is incorrect.
]
System.Net.FileWebResponse..ctor(FileWebRequest request, Uri uri, FileAccess access, Boolean asyncHint) +330
System.Net.FileWebRequest.GetResponseCallback(Object state) +260

[WebException: The filename, directory name, or volume label syntax is incorrect.
]
System.Net.WebClient.DownloadFile(Uri address, String fileName) +375
System.Net.WebClient.DownloadFile(String address, String fileName) +32
Default2.SaveReportsLocally(String CaseNosString) in c:\Inetpub\wwwroot\CP\details.aspx.cs:108
Default2.MergeReportFiles(Object sender, EventArgs e) in c:\Inetpub\wwwroot\CP\details.aspx.cs:90
System.Web.UI.WebControls.Button.onclick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

Is This A Good Question/Topic? 0

Replies To: The filename, directory name, or volume label syntax is incorrect.

#2 Momerath   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1021
  • View blog
  • Posts: 2,463
  • Joined: 04-October 09

Re: The filename, directory name, or volume label syntax is incorrect.

Posted 23 June 2010 - 02:48 PM

Don't double the \\ marks in the file.
Nevermind, that's not it. Hmm... Why do you have an @ in front of the docname?

This post has been edited by Momerath: 23 June 2010 - 02:51 PM

Was This Post Helpful? 0
  • +
  • -

#3 Guest_Tripti*


Reputation:

Re: The filename, directory name, or volume label syntax is incorrect.

Posted 23 June 2010 - 03:13 PM

I saw that in a sample code online so I just tried it. Error is the same with or without @ sign. webClient.DownloadFile takes two input paramaters : string address and string filename, which is what I am giving it.

Thanks.
Was This Post Helpful? 0

#4 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1663
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: The filename, directory name, or volume label syntax is incorrect.

Posted 23 June 2010 - 03:23 PM

I could be wrong but I think \\\\c-n-one\\Reports\\pdf\\ should be \\c-n-one\\Reports\\pdf\\
Was This Post Helpful? 0
  • +
  • -

#5 Guest_Tripti*


Reputation:

Re: The filename, directory name, or volume label syntax is incorrect.

Posted 23 June 2010 - 03:50 PM

when I set my key in web.config is as follows:
<add key ="PDFFileServer" value="\c-n-one\Reports\pdf\"/>


_PDFfilesRootPath = "\\c-n-one\\Reports\\pdf\\"

The error changes to :
Could not find a part of the path 'C:\csi-nas-one\LISReports\pdf\'.

Please note "C:\..."

The double \\ in the key on web.config tells it that it is server\folder\..
Was This Post Helpful? 0

#6 Momerath   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1021
  • View blog
  • Posts: 2,463
  • Joined: 04-October 09

Re: The filename, directory name, or volume label syntax is incorrect.

Posted 23 June 2010 - 06:19 PM

Try putting '/' where you have '\' now. So your string would read "//c-n-one/Reports/pdf/".

As you can tell, we don't use DownloadFile a lot :)
Was This Post Helpful? 0
  • +
  • -

#7 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: The filename, directory name, or volume label syntax is incorrect.

Posted 25 June 2010 - 07:31 AM

If your file is on a share on a remote server, you don't need to use a WebClient. You can use System.IO to handle it.

string remotePath = @"\\c-n-one\Reports\pdf\";
string localPath = @"c:\dev\";
string fileName = "someFile.pdf";

FileInfo fi = new FileInfo(remotePath + fileName);
fi.CopyTo(localPath + fileName);



Edit: The syntax hi-lighting here doesn't understand that @ signifies a verbatim string literal.

This post has been edited by insertAlias: 25 June 2010 - 07:37 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1