SharePoint site test data Automation series--upload files to SharePoint library using PowerShell.

Source: Internet
Author: User

Daily SharePoint site testing, we often have to do a variety of data, and today wrote a few scripts, found themselves writing more and more scripts, so I decided to tidy up, and some of the commonly used reusable methods are published.

Today, let's talk about how to upload files to a SharePoint library using PowerShell, with the following code:

add- pssnapin Microsoft.SharePoint.PowerShellfunction createagendadocumentdata{param ($siteUrl, $listTitle,$filePath,$fileName) $site= get-SPSite $siteUrl $web=$site. RootWeb $List=$web. lists[$listTitle] $folder=$List. RootFolder $File= get-ChildItem $filePath $fileStream= ([System.IO.FileInfo] (get-Item $File. FullName)). OpenRead ()[Microsoft.SharePoint.SPFile] $spFile= $folder. Files.add ($folder. URL +"/"+$fileName, [System.IO.Stream] $fileStream, $true) $spFile. Item.update () $fileStream. Close ()}

The orange font in the above code is the information you need to enter, including the url,list title of SharePoint site, the path to the local file, and the new name you want to upload to SharePoint.

The following methods are used:

" fill in the site URL for the SharePoint sites "   "fill in the title of the list of files you want to uploadand fill in the local file path you want to upload "  -siteurl $siteUrl-listtitle $listTitle-filepath $filePath

You can then see that the file has been uploaded to the specified list (library).

In fact, in the actual operation, sometimes not only to upload files, but also to its location item set relevant field value, this I will be a separate article to explain all the relevant operations.

If you find it helpful, please, I will write a series of articles about implementing SharePoint Automation with PowerShell. You are welcome to communicate with me and ask me questions.

SharePoint site test data Automation series--upload files to SharePoint library using PowerShell.

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.