开发者

c# how to determine full path of file opened

开发者 https://www.devze.com 2023-03-21 09:31 出处:网络
I am programming an 开发者_StackOverflowexcel add in, and I want to be able to determine the full path of the current excel file open.What would the command be to get this as a string?

I am programming an 开发者_StackOverflowexcel add in, and I want to be able to determine the full path of the current excel file open. What would the command be to get this as a string?

Thank You!


First of all you need to somehow get a Workbook exemplar. My example would be obvious, because I've already know where is my file, but if you getting Workbook passed to you from somewhere you can use the same property.

Excel.Application excelApp = new Excel.ApplicationClass();
string workbookPath = "c:/SomeWorkBook.xls";
Excel.Workbook openedWorkbook = excelApp.Workbooks.Open(workbookPath,
            0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "",
            true, false, 0, true, false, false);

Now you can use FullName property to get name of file and all preceding path, or simply "Name" to get only filename: openedWorkbook.FullName

0

精彩评论

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

关注公众号