えええ

Source: Internet
Author: User

usingMicrosoft.SharePoint;usingSystem;usingSystem.Collections.Generic;usingSystem.Configuration;usingSystem.Data;usingSystem.IO;usingSystem.Linq;usingSystem.Net;usingSystem.Text;usingSystem.Threading.Tasks;usingsystem.web;namespace_20150928{classProgram {Static voidMain (string[] args) {            //Console.WriteLine (Httputility.htmldecode ("&lt;div class=&quot; Externalclass261ed404956e49d289332c8d5de50427&quot;&gt;&lt;p&gt;&lt;a href=&quot;/sites /00/0001/siteassets/lists/dialogue/allitems/tcalprojectlist.xlsx&quot;&gt;&lt;img width=&quot; 16&quot; height=&quot;16&quot; Class=&quot;ms-asset-icon ms-rteposition-4&quot; src=&quot;/_layouts/15/images/icxlsx.png&quot; alt=&quot;&quot; /&gt; tcalprojectlist.xlsx&lt;/a&gt;? &lt;/p&gt;&lt;/div&gt; "));            ////string str = "http://baidu.com.cn/hello%20I%27ama Apple/te%27st.txt "; ////console.writeline (str. Length);            //Console.readkey ();            stringMainsite = configurationmanager.appsettings["SiteURL"]; stringSiteURL = Mainsite +"sites/"+"te"+"/"+"Test"+"/"; stringListName ="Test"; stringFolderserverrelativeurl ="/test/test/"; SPFolder folder=createfolderinlist (SiteURL, ListName, Folderserverrelativeurl); Folder= Getsubfoldernewsystem (folder,"Test"); SPFolder foldernew=folder; stringstrURL ="";//Web Service Get Data            stringFileName =""; Stream Stream=downloadattachment (strURL); if(Stream! =NULL{migrationfromfiletofile (foldernew, FileName, stream); }            stringBodystring ="<a href="+ FolderNew.Url.Remove (0, mainsite.length) + FileName +">"+"/_layouts/15/images/icxlsx.png"+"/>"+ FileName +"</a>"; }         Public StaticSPFolder Createfolderinlist (stringSiteURL,stringListName,stringFolderserverrelativeurl) {SPFolder Returnfolder=NULL; using(SPSite site =NewSPSite (siteurl))using(SPWeb Web =site. OpenWeb ()) {SPList list=web.                Lists[listname]; SPFolder folder=list.                RootFolder; string[] Foldernames = Folderserverrelativeurl.split ('/'); foreach(stringFolderNameinchfoldernames) {                    if(!string. IsNullOrEmpty (FolderName)) {BOOLExitfolder =false; if(folder. Subfolders.count >0)                        {                            foreach(SPFolder subfolderinchfolder. Subfolders) {if(SubFolder.Name.Equals (folderName)) {Exitfolder 
    =true; Folder=subfolder;  Break; }                            }                        }                        if(!Exitfolder) {                            //フォルダー made intofolder.                            Subfolders.add (FolderName); Folder=folder.                        Subfolders[foldername]; } }} Returnfolder=folder; }            returnReturnfolder; }         Public StaticSPFolder Getsubfoldernewsystem (SPFolder parentfolder,stringfolderName) {SPFolder subfolder=NULL; Try{subfolder=Parentfolder.subfolders[foldername]; if(!subfolder.exists) {parentFolder.SubFolders.Add (folderName); Subfolder=Parentfolder.subfolders[foldername]; }            }            Catch{parentFolder.SubFolders.Add (folderName); Subfolder=Parentfolder.subfolders[foldername]; }            returnsubfolder; }         Public StaticStream Downloadattachment (stringstrURL)            {Stream stream; Try{WebClient mywebclient=NewWebClient (); Mywebclient.credentials=NewNetworkCredential (configurationmanager.appsettings["Oldusername"], configurationmanager.appsettings["Olduserpassword"], configurationmanager.appsettings["Olddomain"]); byte[] Pagedata =Mywebclient.downloaddata (strURL); Stream=NewMemoryStream (pagedata);                Mywebclient.dispose (); returnstream; }            Catch(Exception ex) {return NULL; }        }         Public Static voidMigrationfromfiletofile (SPFolder foldernew,stringFileName, Stream stream) {SPFile subfilenew=NULL; byte[] contents =Streamtobytes (stream); if(Contents! =NULL) {subfilenew= FOLDERNEW.FILES.ADD (Foldernew.url +"/"+ FileName, Contents,true); }        }         Public Static byte[] streamtobytes (System.IO.Stream Stream) {intMaxSize = Int32.Parse (configurationmanager.appsettings["maxSize"].            ToString ()); using(System.IO.MemoryStream ms =NewSystem.IO.MemoryStream ()) {                byte[] bytes =New byte[maxsize]; intRead;  while(read = stream. Read (Bytes,0, bytes. Length)) >0) {Ms. Write (Bytes,0, read); if(Ms. ToArray (). Length >maxsize) {                        return NULL; }                }                returnMs.            ToArray (); }        }    }}

えええ

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.