SharePoint document libraries are handy for managing everyday documents, and more powerful for creating folders to categorize, usually very simple on the UI screen, click on folders, create a folder can be. However, how to create folders manually, how to create subfolders in a folder.
Project analysis
For a chestnut, I need to upload the document to the document library, and I want the file to be uploaded to a subfolder named after the year, month, day, and the person who uploaded it, such as: 2013-->5 month-->11 Day--> Chen Xiaochun, as shown in the following figure
Click 2013 to enter the current confinement folder
Click on the current month to enter the subfolder named above
Click on the upload person (Chen Xiaochun), you can see our uploaded documents
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/web/sharepoint/
Code implementation
First we finish setting the parameters, initializing the parameters
Gets the annual parameter
string folderyearparameter = DateTime.Now.Year.ToString () + "year";
Gets the monthly parameter
string foldermonthparameter = DateTime.Now.Month.ToString () + "month";
Gets the current logged-on user name:
string currentloginname = SPContext.Current.Web.CurrentUser.LoginName;
Currentloginname = currentloginname.substring (Currentloginname.lastindexof ("\") + 1);
string Currentuserdisplayname;
Getting display name
//When the administrator uploads a problem? Because when the Administrator lands, Displayname=wllgwh\administrator,invalid Path.
SPUser spuser = spcontext.current.web.allusers[spcontext.current.web.currentuser.loginname];
Currentuserdisplayname = Spuser.name;
if (Currentuserdisplayname.contains ("\"))
{
currentuserdisplayname = currentuserdisplayname.substring ( Currentuserdisplayname.lastindexof ("\") +1);
}