subfolder of document library

Jun 29, 2009 at 1:58 PM

hello, you did a great program here !

if i use the program directly in a document library it works perfect, but if i use it in a subfolder the office applications dont save back to sharepoint. could you please help me, check this out or give me a hint. it would be great to use the templates in every subfolder !

many thanks in advance

Jul 21, 2009 at 9:53 AM

I've also encountered the same problem and I can see what's the reason (unfortunatelly I can't solve it myself). In the subfolder, when you save the created document, the dialog "Save As" offers wrong path in the "Save in" control. Actually I think it is random. Sometimes it offers "Desktop" and the other time some other destination. So the document is not saved into the desired library in the desired folder.

I hope I give some helpful feedback to programer to fix it without spending much time.

Before I end my response, thanks to the author for such a simple and great solution.

Bye, bye.

Jul 21, 2009 at 10:10 AM

So the plain "Save" function works for both of you - and attempts to save in the correct folder, but "Save As" shows some local folder?

Jul 21, 2009 at 10:25 AM

it has nothing to do with the "save" or "save as" function. i am working with subfolders in my document library and it is simply not working in the subfolders ! make a folder go in there and try it - you will see what we mean !

many thanks for your reply !!!

Jul 21, 2009 at 10:31 AM

I've tried it many, many times with sub folders in both the template library and document library; that's why I'm trying to wrap my head around what's actually going on in your setup :-)

Are you using the default document library pages (such as doclib/allitems.aspx), or are you accessing it through a list view web part on another web part page? The latter has some serious flaws to it, especially when you're working with several list views on one page - but that's Microsoft's fault, not mine :-)

Jul 21, 2009 at 11:00 AM

i will try to tell you what i did:

i made a document library for the templates (i named it "vorlagen") - this one is used for the templates and has subfolders - this folder is selected in the properties of your application - the template folder is not accessible from any page of the sharepoint main application. thats working very well.

in my main application i made document libraries based on the default document library ( site actions - create - document library) - no web parts or webpart pages. activated your application - can select templates, make a document and save it  back to sharepoint. here it is working perfect.

now i make a new folder in the above library (new - new folder) - go into this folder. i can select a template, make the document but if i want to write it back to sharepoint (save, save as or simply close) i get a local directory and not the sharepoint server.

hope for your help - many thanks

Jul 22, 2009 at 8:46 AM

When I'm in the library ROOT folder:

1. New / Templates / MyTemplate.docx -> Word opens

2. When I close Word, opens dialog "Save As"

3. In the control "Save in:" is the correct path to my share point library ROOT folder.


When I'm in the library subfolder:

1. New / Templates / MyTemplate.docx -> Word opens

2. When I close Word, opens dialog "Save As"

3. In the control "Save in:" is the path to the "Desktop" (sometimes some other path) and not the path to my library subfolder.

Of course, the file is saved to the Desktop and it does not dissaper as sombody would say (only the subfolder is empty).

The same problem is if I use the comand "Save" (not only "Save As"). I can send you the pictures directly (I can't post them here).

Jul 22, 2009 at 8:55 AM

we detected exactly the same problem - just used other words to explain it ...

Jul 23, 2009 at 10:58 AM
Edited Jul 23, 2009 at 11:05 AM

Hi - first of all, thanks for all the effort you have put in this project, Einar. It was a really lifesaver in one of my project (I had a doc lib with about 70 templates... go wonder what I would have done if I had to use content types...).


Second, I think I have discovered the cause to the problem detected in this post. Seems the miss-beaviour is caused by a wrong folder url passed to the CreateNewDocumentWithProgID function.

From what I have gatered looking at the source code, you use a method GetRootFolder to find the "url" of the current folder shown by the ListViewWebPart. Inside the method, you read a private variable of the wp. Now, in all my test (I had the same problem) the url stored in that variable (rootfolder) was SERVER relative.

ie - if I am looking at the subfolder "folder1" of the doc lib : http://moss/sites/WebSite/DocLib, the variable returned "sites/WebSite/DocLib/folder1". That value is then concatenated with SPContext.Current.Web.Url, returning http://moss/sites/WebSite/sites/WebSite/DocLib/folder1.

I have made a temp fix - free to use it if you like (and free to improve it if you can think of a better way to fix the url)

public static string GetRootFolder(this ListViewWebPart self, bool relative)
            var rootFolder =
                 self.GetType().GetField("rootFolder", BindingFlags.NonPublic | BindingFlags.Instance)
            if (!string.IsNullOrEmpty(rootFolder))
	//Temp Fix: rootFolder seems to be a server relative url,  I will try to make it absolute
                string serverUrl = SPContext.Current.Web.Url.Replace(
                    SPContext.Current.Web.ServerRelativeUrl, "");
                rootFolder = serverUrl + rootFolder;

	// now rootFolder is an absolute url
	//so to make it relative I simply replace the Web.Url part with "".
                return (relative ? rootFolder.Replace(SPContext.Current.Web.Url, "") : rootFolder);  
                //return (relative ? "" : SPContext.Current.Web.Url) + rootFolder;
            return (relative ? "" : SPContext.Current.Web.Url) + "/" + self.GetList().RootFolder.Url;

The class is ListViewWebPartExtensions, in the folder Code/Libraries. Still have to test if some sharepoint configuration (publishing feature?) can make that url absolute in some cases and server relative in anothers

Hope this info will prove usefull, and thank you again for this project.

 (.. edited, hope to have fixed the layout now)

Jul 23, 2009 at 11:21 AM

Great job Arran!

I tried your fix... it works great!!!

Jul 23, 2009 at 11:37 AM

Thanks for taking time to look into the issue, Arran. I'll verify the fix, and incorporate it in the next change set.

Greatly appreciate others taking time to debug and hotpatch - I'm knee deep in other projects at the moment, so until my general workload declines, public domain stuff such as this won't get the attention it deserves.

Jul 23, 2009 at 1:22 PM

New working set and downloadable installation package released, hopefully solving this issue once and for all.

Jul 23, 2009 at 1:36 PM

works perfect !!!

many thanks for the fast solution in your great application !!!