Geoff Overfield Geoff Overfield - 1 year ago 91
C# Question

Receiving IOException

I'm getting the

Error when I try this, and I'm not sure what I'm doing wrong:

enter image description here

This is my code:

FileStream fStream = new FileStream(PDFFilePath(), FileMode.CreateNew, FileAccess.ReadWrite);


private string PDFFilePath()
m_sFilePath = "C:/Pictures/";
return m_sFilePath;

What am I missing?

I'm using this
to save PDF documents using the Pdf.Select NuGet. It uses a method:

PdfDocument.Save(Stream stream);

Mat Mat
Answer Source

I think you should be specifying your path this way:

private string PDFFilePath(string filename)
    m_sFilePath = @"C:\Pictures\" + filename;
    return m_sFilePath;

Like @Reisclef said, you have to provide a file path, not a directory. Since you're using FileMode.CreateNew, it has to be a new file, so you might also want to use File.Exists(m_sFilePath) before returning.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download