Default save location of a document initiated in SharePoint

1 minute read

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;
        }