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

17,908

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)

Share:
17,908
NealR
Author by

NealR

Updated on June 11, 2022

Comments

  • NealR
    NealR almost 2 years

    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);