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);
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With