OreuhNation
OreuhNation

Reputation: 41

“The given path's format is not supported.”

I am trying to create a PDF via C# using iTextSharp

if (emp.FormDesc == "FormOne")
   {
      string filePath = @"\\G:\SharedDrive\Forms\FormOne\" + filename;

       // Write out PDF from memory stream.
       using (FileStream fs = File.Create(filePath))
        {
           fs.Write(content, 0, (int)content.Length);
        }
    }

I am returning this string

filePath = "\\\\G:\\SharedDrive\\Forms\\FormOne\\11-23-2020.pdf"

but I keep getting the error message “The given path's format is not supported.”

Any ideas? My syntax seems correct.

Thank you.

Upvotes: 0

Views: 2252

Answers (2)

osman Rahimi
osman Rahimi

Reputation: 1497

The better and saffer way is using Path.Combine like below:

 string filePath = Path.Combine("G:\SharedDrive\Forms\FormOne", filename);

Upvotes: 1

JesseChunn
JesseChunn

Reputation: 585

Change this:

string filePath = @"\\G:\SharedDrive\Forms\FormOne\" + filename;

To this:

string filePath = @"G:\SharedDrive\Forms\FormOne\" + filename;

Or if it is a network share, then something like this:

string filePath = @"\\SharedDrive\Forms\FormOne\" + filename;

where "SharedDrive" is the name of the network share.

(edited in response to first comment below)

Upvotes: 3

Related Questions