Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am new to Sharepoint Server, Do we have any utility to upload files from ASP.NET application.

Could you please provide your valuable answers?

share|improve this question
add comment

2 Answers

You can write some custom code to do it. You could use the SharePoint API if you are on the same server or use WebServices

Here is the sample code assuming that you know the url of the document library and you are uploading the document to the root folder. You will have to add Microsoft.SharePoint.dll as reference to your ASP.NET project

        using (SPSite siteCollection = new SPSite(url))
        {
            using (SPWeb spWeb = siteCollection.OpenWeb())
            {
                SPList spList = spWeb.GetList(url);

                string fileName = "XXXX";
                FileStream fileStream = null;
                Byte[] fileContent = null;

                try
                {
                    string docPath = XXXX; //physical location of the file
                    fileStream = File.OpenRead(docPath + fileName);
                    fileContent = new byte[Convert.ToInt32(fileStream.Length)];
                    fileStream.Read(fileContent, 0, Convert.ToInt32(fileStream.Length));

                    spList.RootFolder.Files.Add(spList.RootFolder.Url + "/" + fileName, fileContent, true);
                    spList.Update();
                }
                catch(Exception ex)
                {

                }
                finally
                {
                    if (fileStream != null)
                    {
                        fileStream.Close();
                    }
                }
            }
        }
share|improve this answer
 
You can also use SPFolder.Add(url, Stream, overwrite) instead of reading the whole file into memory (which can lead to performance issues if you plan to upload large files) –  Marek Apr 19 '12 at 8:07
add comment

look at this blog post. By Bil Simser.

There seemed to be a lot of argument about using Web Services, lists, and all that just to upload a document. It can't be that hard. After spending a little time on Google (google IS your friend) I found various attempts at uploading documents through regular HTTP PUT commands. Here's the one that finally worked in a simple, single function:...

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.