Create a folder in the moss document library or image library

Source: Internet
Author: User

Using system; <br/> using system. data; <br/> using system. configuration; <br/> using system. collections; <br/> using system. web; <br/> using system. web. security; <br/> using system. web. ui; <br/> using system. web. UI. webcontrols; <br/> using system. web. UI. webcontrols. webparts; <br/> using system. web. UI. htmlcontrols; <br/> using system. componentmodel; <br/> using Microsoft. sharePoint; <br/> using Microsoft. sharep Oint. webcontrols; </P> <p> Public partial class wsgl_controls_createfolder: system. web. UI. usercontrol <br/>{< br/> # region defines variables and attributes </P> <p> private spsite SPS; <br/> private spweb spw; <br/> private splist list; <br/> private splistitemcollection items; </P> <p> private string folderurl; <br/> /// <summary> <br/> // The complete path of the folder, for example, "/DEPT/GSB/doclib5/test" <br/> // </Summary> <br/> [category ("control custom attribute")] <br /> [Description ("Path of the parent folder of the new folder, for example,/DEPT/GSB/doclib5/test")] <br/> [browsable (true)] <br/> Public String folderurl <br/> {<br/> Get <br/>{< br/> return folderurl; <br/>}< br/> set <br/>{< br/> folderurl = value; <br/>}</P> <p> private string Foldername; <br/> /// <summary> <br/> // folder name <br/> /// </Summary> <br/> [category ("control from define attributes ")] <br/> [description ("Name of the new folder")] <br/> [browsable (true)] <Br/> Public String Foldername <br/> {<br/> Get <br/> {<br/> return Foldername; <br/>}< br/> set <br/> {<br/> Foldername = value; <br/>}< br/> # endregion </P> <p> protected void page_load (Object sender, eventargs E) <br/>{< br/> SPS = getwebsite ("/" + configurationmanager. appsettings ["Site"] + "/", this. context); <br/> SPs. allowunsafeupdates = true; <br/> spw = SPs. openweb (); <br/> S PW. allowunsafeupdates = true; <br/>}< br/> protected void btnok_click (Object sender, eventargs E) <br/>{< br/> // create a folder <br/> createfolder (folderurl, Foldername ); <br/>}</P> <p> // <summary> <br/> // obtain the site from the configuration parameters <br/> /// </ summary> <br/> /// <Param name = "siteurl"> </param> <br/> /// <Param name = "context"> </param> <br/> // <returns> </returns> <br/> Public spsite getwebsite (string siteurl, system. Web. httpcontext context) <br/>{</P> <p> spsite S = NULL; <br/> If (siteurl! = "" & Siteurl! = NULL) <br/>{< br/> // process the writing of various addresses <br/> If (! Siteurl. toupper (). startswith ("HTTP") // if it is in the relative address format <br/>{< br/> string thisurl = spcontrol. getcontextsite (context ). URL; <br/> int Index = thisurl. indexof ("/", 8); <br/> If (index> 0) // if the address is the root directory <br/>{< br/> siteurl = thisurl. substring (0, index) + siteurl; <br/>}< br/> else // if this address is not for the site <br/>{< br/> siteurl = thisurl + siteurl; <br/>}</P> <p >}< br/> S = new spsite (siteurl); <br/>}</P> <p> return S; <br/>}</P> <p> # region create a folder <br/> /// <summary> <br/> // create a folder in the specified document library folder <br/> /// </Summary> <br/> // <Param name = "folderurl"> </param> <br/> // <Param name = "Foldername"> </param> <br/> protected void createfolder (string oldfolderurl, string newfoldername) <br/>{< br/> spfolder parent = spw. getfolder (oldfolderurl); <br/> If (parent. exists) <br/>{< br/> List = spw. lists. getlist (parent. parentlistid, true); <br/> splistitem item = List. folders. add (oldfolderurl, spfilesystemobjecttype. folder); <br/> item ["name"] = newfoldername; <br/> item. update (); <br/>}< br/> # endregion <br/>}< br/>

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.