Default save location of a document initiated in SharePoint

For the last couple of day’s I have been developing word templates. In these templates I had to get the url of the site in which the document was initiated. By default when you click the new button in a document library of SharePoint and create the document in word and you save the document the save dialog will open with the correct library were you clicked on new. In the available object you have with word development I could not find a solution for this problem. But then I thought word has had to be opened with a specific argument so I went looking in de command line arguments. So to find the default save location when you initiated a new document from word you have to do the following.

 

        public static string GetInitiationLocation()
        {
            string retVal = string.Empty;
            string[] commandLineArgs = Environment.GetCommandLineArgs();
            if (commandLineArgs.Count() >= 3)
            {
                string[] fArgument = commandLineArgs[2].Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries);
                if (fArgument.Count() == 3)
                {
                    retVal = fArgument[2];
                }
            }
            return retVal;
        }

Related Posts

SharePoint Rest API Handler SharePoint contains a lot of Rest API’s that can be used for many scenario’s. You could use them for example in desktop and windows phone applications...
User automatically removed from SharePoint Group During my current project we received an access request from a user. We did what we normally do, we checked the request and added the user in the appr...
Warm Up Form Based Web Application Normal warm up scripts for SharePoint open a site object or web object and make a request to that specific site. When you use form based authenticatio...
Load modules by default when opening PowerShell At the moment we are working a lot with PowerShell in combination with SharePoint. Over time we created a lot of usable functions that were not availi...
PowerShell Scripts During my current project we are using a lot of PowerShell scripts to administrate the environment and make development easier for us. In this post...
TFS and SharePoint Builds including Automatic deployments – Part 1 Part 1 of this series will instruct how to configure your build server for building SharePoint projects. In Part 2 we will discuss the automatic deplo...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.