3

I'm trying to develop an Word-AddIn where I can upload a file, or where I could make changes to the file itself. I can do that with any File on the Local NTFS Windows Filesystem. But when a File is located to any "OneDrive"-Folder it won't work, as the file-Document path starts with:

https://companyname-my.sharepoint.com/personal/name_whatever/Documents

according to the return values of:

var doc = Globals.ThisAddIn.Application.ActiveDocument;

        MessageBox.Show("Document Name : " + doc.Name);
        MessageBox.Show("Document Full Name : " + doc.FullName);
        MessageBox.Show("Document Path : " + doc.Path);

rather than expected to be:

C:\Users\myname\OneDrive-My_Company_Name\Documents

So basically the local folder is not callable. So does anybody has already faced this kind of issue?

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
Maik
  • 1,582
  • 3
  • 12
  • 13
  • **it won't work** what wont work ? In my opinion you don't need to know where the file is located. Are you unable to save the document after changing ? The call `Save` if you want to save a copy `SaveAs` if you want to save a copy in the same folder of the source doc you will need to check OneDrive API ; perhaps [this link](https://stackoverflow.com/questions/31195891/saving-a-shared-docx-from-onedrive-to-original-onedrive-location-in-ms-word) will help – Fabrice T Jul 19 '19 at 18:00
  • I don't want to `save` a document. All I want is, when the Document is open in Word, and I want to upload it to a webserver, or any other destination, the code of the Add-In will check the current location of the Document and then tries to get it and upload it to the destination (ex. Webpage - upload via POSTMethod). So in case the Document is on a Folder for example called `C:\TEMP` it is working without any issue. But when the File is in the Local OneDrive folder on the Box, it will end up in the described issue. – Maik Jul 19 '19 at 21:54
  • In your problem what I can't understand is where the actual issue is? You described "the code of the Add-In will check the current location of the Document" , "tries to get it" & "upload it to the destination" mainly 3 scenarios. Where the actual problem exist? Any code sample? – Ramesh Perera Apr 27 '22 at 11:24
  • You can get the local path of your document with VBA using [this solution](https://stackoverflow.com/a/73577057/12287457). I don't know how difficult it would be to port the code to .NET. If it is too difficult to port that solution, you could definitely do it with [this one](https://stackoverflow.com/a/72736924/12287457), which is not 100% reliable though, but will still work in almost all real-world cases. – GWD Sep 05 '22 at 23:48
  • A VB.NET solution for this problem now exists [here](https://gist.github.com/guwidoe/bc875f4f25e0e970c62959d3c59da1d6). The solution is a port of [this function](https://gist.github.com/guwidoe/038398b6be1b16c458365716a921814d) originally written in VBA. Performance is a little worse than in the VBA version because some functionality of VBA is not available in V.NET and I didn't want to change the code too much to reduce the effort for porting. Maybe this can be further ported to C# without too much effort... – GWD Oct 23 '22 at 16:27

1 Answers1

0

You can use the Save or SaveAs methods of the Document to save the document on the local folder.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45