Getting Path of File in OneDrive/Sharepoint

27 views
Skip to first unread message

Terry Aney

unread,
May 26, 2021, 2:37:20 PM5/26/21
to Excel-DNA
I'm using the following code to determine the path of a file...

```
public static WorkbookEx ActiveWorkbook
{
get
{
var name = (string)XlCall.Excel( XlCall.xlfGetDocument, (int)GetDocumentType.ActiveWorkbook );
var path = "";

try
{
path = (string)XlCall.Excel( XlCall.xlfGetDocument, (int)GetDocumentType.ActiveWorkbookPath, name );
}
catch { }

name = Path.Combine( path, name );

return new WorkbookEx( name );
}
}
```

Then the constructor of WorkbookEx is as follows:

```
public WorkbookEx( string filename )
{
try
{
var fileInfo = new FileInfo( filename );
Name = fileInfo.Name;
Path = fileInfo.DirectoryName;
}
catch ( Exception ex )
{
throw new ApplicationException( "Unable to open: " + filename, ex ); ;
}
}
```

However, the path returned by `(string)XlCall.Excel( XlCall.xlfGetDocument, (int)GetDocumentType.ActiveWorkbookPath, name );` is "https://conduent-my.sharepoint.com/personal/terry_aney_conduent_com/Documents".  FileInfo doesn't handle a file name in this format.  Is there a way to get the "c:\" path of the file with XllCall?

Terry Aney

unread,
May 27, 2021, 11:25:27 AM5/27/21
to Excel-DNA
Currently, I'm doing what I described here: https://stackoverflow.com/a/67725281/166231
Reply all
Reply to author
Forward
0 new messages