0

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

Everything 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?

1
  • Looks like the file is open already (your app has it open for modification). Commented Sep 12, 2010 at 23:37

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.