To upload a document to a subfolder of a document library using C # code in SharePoint

Source: Internet
Author: User
Tags datetime tostring

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.