FileStream - “The given path's format is not supported”

泄露秘密 提交于 2019-12-10 14:37:32

问题


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

回答1:


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)



来源:https://stackoverflow.com/questions/21468159/filestream-the-given-paths-format-is-not-supported

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!