This article explains how to upload a file in a Document Library.In SharePoint, library files are uploaded using the Add method on the Files property of a SPWeb like this:SPContext.Current.Web.Files.Add(docLibrary.RootFolder.Url + "/" + fileUpload.FileName, contents);I have created a webpart that uploads a file provided by the user to a SharePoint library.Use the following procedure to create a sample of doing it.1. Create an empty SharePoint project and add a webpart. 2. Modify the code as below:
3. Build the solution and deploy.4. Go to the Site Page library and create a page as in the following:5. Add the Webpart.6. Try to upload a document in the library. You will get the error as below:7. Edit the webpart and fill in the name of the Document Library where you want to add the document through this page's webpart.8. Now upload a file.9. Navigate to the Document Library. You will find your uploaded document in the library.ConclusionThis article explained how to upload a document in a Document Library using a custom webpart property.
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: