Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FileStream - "The given path's format is not supported"

I'm trying to use EPPlus to save a spreadsheet on our LAN. I'm using a FileStream object to do this, however whenever I attempt to instantiate the object I get the error

The given path's format is not supported

C#

    private static string _fileName = "ErroredRows_";
    private static string _results =
        @"\\prdhilfs03\l&i-sales&mkt\WORKAREA\Agencyservices\Shared\AIC\Analysts_and_Reporting\Realignments\2014\MassUpdateTesting\Results\";

    public static void WriteSpreadsheet(Dictionary<DataRow, string> errors)
    {
        //Create download Destination
        string filePath = System.IO.Path.Combine(_results, _fileName + DateTime.Now.ToString("yyyy-MM-dd_HH:mm:ss") + ".xlsx");

        FileStream newFile = new FileStream(filePath, FileMode.Create, FileAccess.Write);

        //Construct new Excel package
        ExcelPackage pck = new ExcelPackage(newFile);

        //Instantiate workbook object
        var ws = pck.Workbook.Worksheets.Add("Query1");

Here's the contents of the filePath string variable.

\\\\prdhilfs03\\l&i-sales&mkt\\WORKAREA\\Agencyservices\\Shared\\AIC\\Analysts_and_Reporting\\Realignments\\2014\\MassUpdateTesting\\Results\\ErroredRows_2014-01-30_13:46:33.xlsx

This line throws the error mentioned above:

FileStream newFile = new FileStream(filePath, FileMode.Create, FileAccess.Write);
like image 685
NealR Avatar asked Jan 30 '14 21:01

NealR


1 Answers

You can't have : in your filename or path.

What i would do if i were you is this:

DateTime.Now.Ticks.ToString()

instead of

DateTime.Now.ToString("yyyy-MM-dd_HH:mm:ss")

Anyway, you can keep your own logic but you have to remove : (instead use - or _ for example)

like image 115
Justin Iurman Avatar answered Nov 06 '22 07:11

Justin Iurman