Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 750255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:31:48+00:00 2026-05-14T14:31:48+00:00

Could you help me for how to add a file to the Sharepoint document

  • 0

Could you help me for how to add a file to the Sharepoint document library? I found some articles in .NET, but I didn’t get the complete concept of how to accomplish this.

I uploaded a file without metadata by using this code:

if (fuDocument.PostedFile != null)
                {
                    if (fuDocument.PostedFile.ContentLength > 0)
                    {
                        Stream fileStream = fuDocument.PostedFile.InputStream;
                        byte[] byt = new byte[Convert.ToInt32(fuDocument.PostedFile.ContentLength)];
                        fileStream.Read(byt, 0, Convert.ToInt32(fuDocument.PostedFile.ContentLength));
                        fileStream.Close();


                        using (SPSite site = new SPSite(SPContext.Current.Site.Url))
                        {
                            using (SPWeb webcollection = site.OpenWeb())
                            {
                                SPFolder myfolder = webcollection.Folders["My Library"];
                                webcollection.AllowUnsafeUpdates = true;
                                myfolder.Files.Add(System.IO.Path.GetFileName(fuDocument.PostedFile.FileName), byt);

                            }
                        }
                    }
                }

This code is working fine as is, but I need to upload a file with metadata. Please help me by editing this code if it is possible. I created 3 columns in my document library.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:31:48+00:00Added an answer on May 14, 2026 at 2:31 pm

    SPFolder.Files.Add returns a SPFile object

    SPFile.Item returns an SPListItem object

    You can then use SPlistItem[“FieldName”] to access each field (see bottom of SPListItem link)

    So adding this into your code (this is not tested, but you should get the idea)

    SPFile file = myfolder.Files.Add(System.IO.Path.GetFileName(document.PostedFile.FileName);
    SPListItem item = file.Item;
    item["My Field"] = "Some value for your field";
    item.Update()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope someone could help me on this. I want to add a month
I could use some help writing a regular expression. In my Django application, users
I could use some help creating an XSL template that will take a string
I created a file and add some contents into it. Then, I want to
I need to add some files to the VSS through the command line, but
I've seen a couple examples out there that could possibly help me, but I
Is there something available that could help me convert a XSD into SQL relational
I'm kinda stuck with this one so I hoped someone could help me. I
OK, if anyone could help me with this I'd be much appreciative. If you
I recently ran into a problem that I thought boost::lambda or boost::phoenix could help

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.