开发者

Sharepoint: difference between Title, Name and DisplayName for library folders

开发者 https://www.devze.com 2022-12-15 23:09 出处:网络
Sorry if this has been asked elsewhere. I have looked but can\'t find any definitive answers. I\'m writing an app for SharePoint 2010 that needs to create folders in a document library; one for each

Sorry if this has been asked elsewhere. I have looked but can't find any definitive answers.

I'm writing an app for SharePoint 2010 that needs to create folders in a document library; one for each "job" that the app开发者_StackOverflow中文版 processes, as a place to put the job output. But, I'm having problems with folder name collisions. Each "job" is encoded as an xml file in another SharePoint list. For example, it might contain an xml file called "from docx to pdf.xml". So far I have the app creating subfolders in the output list using the job files name minus the extension. So, a folder called "from docx to pdf" in this case. But, some time later, the app might have to re-process the exact same job. I want to be able to have another subfolder in the same list as the first, with the exact same name visible to the user in a browser...

Can you do this in SharePoint lists? It seems ordinary SPListItems have Name, DisplayName and Title properties. Obviously, one of these must be unique, so that SharePoint can uniquely identify that item. But which is it? And does the same apply to SPFolder items in a list? I guess here I want to have something like duplicated folder display names, but unique internal names. Do you have any ideas on how to do this? So far, my crappy method goes something like this:

 private SPFolder CreateSubFolder(SPList list, string visibleFolderName)
    {           
        // create a new folder under the root folder
        SPListItem newFolder = list.AddItem("", SPFileSystemObjectType.Folder, visibleFolderName);            
        newFolder.Update();               
        return newFolder.Folder;
    }

This obviously doesn't work. Any ideas on how to alter to have the same visible name, but diff internal names (perhaps using Guids...)?:D Thanks in advance.


Like in ordinary file systems, folders under the same sub folder must be unique. Thus, the last parameter of the Add() method should be unique, because it indicates the folder name.

You can safely asssign a duplicate title after creating the folder, using this piece of code:

SPListItem newFolder = list.Items.Add("", SPFileSystemObjectType.Folder, uniqueFolderName);
newFolder["Title"] = "New Folder"; // Can be duplicated
newFolder.Update();

Now you will have folders with same titles but different names. Still, when you try to browse these folders from Windows Explorer or SharePoint default list view, it will show you the folder name (which is unique), not the titles (which you want). So you need to create a custom view and display the title field instead of the folder name.

0

精彩评论

暂无评论...
验证码 换一张
取 消