开发者

writing to disk: File access denied

I try to write my data to an Excel file. I'm using workbook method SaveAs. This is the code:

string FN = "C:\\Users\\Documents\\dane1.xlsx";
WB.SaveAs(FN, Excel.XlFileFormat.xlWorkbookNormal,
            Missing.Value, Missing.Value, Missing.Value, Missing.Value,
            Excel.XlSaveAsAccessMode.xlShared,
            Missing.Value, Missing.Value, Missing.Value,
            Missing.Value, Missing.Value);

Everyt开发者_高级运维hing is OK while the first parameter is hardcoded. When I try use a reference to object where I'm keeping path and file name (I've got it from SaveFileDialog) my application return me an exception:

File access denied".

What's wrong? Does anybody know how this can be avoided?


IF you're running Vista / Windows 7 you may need to run your application as Administrator to save to c:\Users\Documents (which generally doesn't exist)

Did you mean c:\Users\'username'\Documents?

in C# you could use Environment.GetEnvironmentVariable("userprofile") to get the users folder (ie c:\Users\Postman) - which is like type %userprofile% into run.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜