locked
Get location of Default File Path when loaded from SharePoint RRS feed

  • Question

  • Hi

    I have a document that I am using as a content type in SharePoint. It has a VSTO addin that does some stuff like get information from web services etc. The issue is that I need to get where the file was downloaded from, ie the Document Library that it came from in SharePoint

    I looked through the Application.Options.get_DefaultFilePath(etc) to see if it would show me where it can from but it keeps pointing back to Documents and Settings tho if you call the Save method you get pointed towards the SharePoint site it came from.

    Also tried looking at Environment.CommandLine but I am getting the winword.exe embedded tho in development it comes back with the location of .DOTX file as a command line /z etc.

    Any ideas on how to get this information.
    Blog: http://www.certsandprogs.com

    70-536 Objectives List with MSDN Links
    70-505 Objectives List with MSDN Links
    70-562 Objectives List with MSDN Links
    70-433 Objectives List with MSDN Links
    Wednesday, December 9, 2009 12:53 PM

Answers

  • Hi Niall

    Well, you're really off-topic with this in the VSTO forum - no Sharepoint here. The forum's Please Read First message will tell you more about what VSTO is.

    About the only other suggestion I can make, given that the document has been created from a template, is to check the FullName and/or Path of objectDocument.AttachedTemplate. But I have no idea how this will work when the template is on SharePoint.
    Cindy Meister, VSTO/Word MVP
    Wednesday, December 9, 2009 3:47 PM

All replies

  • Hi Niall

    Have you tried querying the FullName or Path properties of the Document object?

    DefaultFilePath is the path where Word will save a new document; it has no affect on an existing one that's been opened.
    Cindy Meister, VSTO/Word MVP
    Wednesday, December 9, 2009 2:56 PM
  • Hi Cindy

    Thanks for the reply.

    What I am looking for is the location of the document library in SharePoint that Word will save to when the user tries to save it for the first time. It is not an existing document but a brand new one, that is opened when the user clicks New in the Document Library. The template has been uploaded as a new content type for that library and I want to get the document library that it came from or as previously stated, where the initial save location that it will be saved to.

    I am checking in the DIP in the Server properties to see whats happening as well..

    I looked at some of the quick parts as well, because when you use the fields in the Quick Parts button, you can select templates and include path and that gives the template path which is http://server/doclib/forms/contentype/template.dotx which is partly when I am looking for.




    Blog: http://www.certsandprogs.com

    70-536 Objectives List with MSDN Links
    70-505 Objectives List with MSDN Links
    70-562 Objectives List with MSDN Links
    70-433 Objectives List with MSDN Links
    Wednesday, December 9, 2009 3:27 PM
  • Hi Niall

    Well, you're really off-topic with this in the VSTO forum - no Sharepoint here. The forum's Please Read First message will tell you more about what VSTO is.

    About the only other suggestion I can make, given that the document has been created from a template, is to check the FullName and/or Path of objectDocument.AttachedTemplate. But I have no idea how this will work when the template is on SharePoint.
    Cindy Meister, VSTO/Word MVP
    Wednesday, December 9, 2009 3:47 PM
  • The attachedTemplate may be the trick I am looking for. If that has the path then happy days.

    The other thing I was looking at was the CustomXml in the Document Properties as that contains Server information.

    Sorry for the wrong forum.. Its VSTO code and Word Object model stuff I was looking at rather than SharePoint so hence why I thought here
    Blog: http://www.certsandprogs.com

    70-536 Objectives List with MSDN Links
    70-505 Objectives List with MSDN Links
    70-562 Objectives List with MSDN Links
    70-433 Objectives List with MSDN Links
    Wednesday, December 9, 2009 8:37 PM
  • Hi Cindy

    Thanks for the advice and pointer in the right direction.. the AttachedTemplate.Path comes back as http://server/lib/forms/CType/ which is perfect as I can parse that back to where I need to.

    N
    Blog: http://www.certsandprogs.com

    70-536 Objectives List with MSDN Links
    70-505 Objectives List with MSDN Links
    70-562 Objectives List with MSDN Links
    70-433 Objectives List with MSDN Links
    Thursday, December 10, 2009 9:43 AM
  • Argh! This same problem is driving me nuts!

    I can't rely on AttachedTemplate, I'm afraid - it only works if there is a template specifically assigned to the content type that is being created.

    I think that this issue is regarding Word and VSTO, so I will persist with the issue in this forum, if that's ok.

    Word knows where we want to save the new document, as this is the initial directory when the save as dialog is opened from the standard Save As command.

    If I show a Save As dialog by doing something like this:

     

    FileDialog saveDialog = Application.get_FileDialog(MsoFileDialogType.msoFileDialogSaveAs);

     

    saveDialog.Show();

    Then it does not open to the same location as when using the standard Save As button.

    I've scoured the properties of the Application, Document and DocumentClass objects looking for a DefaultSavePath or similar, without success.

    I've trawled through the xml in the CustomXMLParts and found some great data on the SharePoint content type, but no information about the location of the library from where it was created.

    Word HAS to know, as the path is used when the save as dialog is opened and the document is initialized using the path as a parameter...

    ...I've looked at the problem from the other end (how SharePoint creates the document from script), and found that it creates an ActiveX object called SharePoint.OpenDocuments.2 (or SharePoint.OpenDocuments.3) and calls a CreateDocument method, passing in the save location as a parameter.

    After this I am lost.  I don't know what the CreateDocument method actually does with that path or how Word stores it.

    I really, really need to get that path from Word VSTO!

    Thanks in advance for any help you can offer,

    Dave

    JJBongo
    Friday, February 26, 2010 11:39 AM
  • This should help you out:

    http://blogs.sharepoint247.com/blogs/arildaarnes/archive/2007/12/06/23.aspx

     Environment.CommandLine is the key. Parse the string for just about the only info word gets from sharepoint that I can tell.

     

    • Proposed as answer by JJBongo Wednesday, June 9, 2010 2:31 PM
    Monday, May 24, 2010 8:20 PM
  • Brilliant, this solves this problem!

    Thanks!

    However VSTO should really expose this in a more useful way!  Perhaps VSTO for Office 2010 will improve support for SharePoint.


    JJBongo
    Wednesday, June 9, 2010 2:31 PM
  • I'm having the same problem but parsing Environment.CommandLine has not solved it because it only seems to return the initial command line used to open Word. So it works fine if the SharePoint doc is the first one opened, but if I already have a document opened from a local folder the defaultsavelocation parameter is missing, and if I already have a document opened from another SharePoint library the defaultsavelocation will point to that library. Any other ideas?

    Thanks.
    Thursday, June 17, 2010 10:31 AM
  • I'm having the same problem but parsing Environment.CommandLine has not solved it because it only seems to return the initial command line used to open Word. So it works fine if the SharePoint doc is the first one opened, but if I already have a document opened from a local folder the defaultsavelocation parameter is missing, and if I already have a document opened from another SharePoint library the defaultsavelocation will point to that library. Any other ideas?

    Thanks.

    Arg. I just came across this problem for us today. If anyone finds the solution, please let us know. I'll keep looking into it myself.

    Friday, July 23, 2010 8:09 PM
  • Hi,

    I just posted a similar solution in this thread, with code sample. Could you check to see if this works for you?

    http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/d933e082-3072-41e1-9c59-33bf9ac9f405

     

    Frank

    Wednesday, August 18, 2010 12:54 PM
  • Hi,

    If you cannot rely on objectDocument.AttachedTemplate then you can use Environment.CommandLine and get defaultsavelocation. However, SharePoint does not send defaultsavelocation when Word already is opened and you create a document from SharePoint library.

    I have finally figured it out that from where Word reads the defaultsavelocation that works in all above scenarios. It actually reads from Registry Key for example for Word 2010 [HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Word\Recent Templates] and Template1. It should look like in my senirio “_WSS_http://sharepoint/projects/C001/Forms/Letter/Letter.dotx*http://sharepoint/projects/C001/9121000003/Documents”. It should be changed every time you create a document from SharePoint Document Library.

    I hope really that it will help you allJ

    Aftab Ahmad

    Sunday, January 13, 2013 1:53 PM