-2

I want to give option to user on .aspx page to u

I created an ASPX form page. There is an option to upload / download the document for storage.

My requirement is,

I need both upload and download button in the same page.

While clicking the upload from the .aspx page the document should store in SharePoint 2010 document library.

While clicking download from .aspx page it should download from the document library, using the document library for Document storage.

How to achieve this?

Thanks

  • What have you done up until this point on this solution? What type of research have you done? – Robban1980 Sep 30 '14 at 6:18
  • hi robban1980, i tried to upload the document using the client object model and all the documents uploaded successfully from .aspxpage to sharepoint, for Download i how to achive it... – Sundhar Sep 30 '14 at 7:02
1

If your form is hosted inn SharePoint, You can use server object model for this But as per your query you can trying to host the page in your asp.net web forms application, so for this you can use client object model:

Use following method to upload document:

public void UploadDocument(string siteURL, string documentListName,
string documentListURL, string documentName,

byte[] documentStream)
{

using (ClientContext clientContext = new ClientContext(siteURL))
{        

//Get Document List
List documentsList = clientContext.Web.Lists.GetByTitle(documentListName);

var fileCreationInformation = new FileCreationInformation();
//Assign to content byte[] i.e. documentStream

fileCreationInformation.Content = documentStream;
//Allow owerwrite of document

fileCreationInformation.Overwrite = true;
//Upload URL

fileCreationInformation.Url = siteURL + documentListURL + documentName;
Microsoft.SharePoint.Client.File uploadFile = documentsList.RootFolder.Files.Add(
    fileCreationInformation);

//Update the metadata for a field having name "DocType"
uploadFile.ListItemAllFields["DocType"] = "Favourites";

uploadFile.ListItemAllFields.Update();
clientContext.ExecuteQuery();

}
}

Use following to download the document from library.

public Stream DownloadDocument(string siteURL, string documentName)
{

ListItem item = GetDocumentFromSP(documentName);
if (item != null)

{
using (ClientContext clientContext = new ClientContext(siteURL))

{
FileInformation fInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext,
    item ["FileRef"].ToString());            

return fInfo.Stream;
}

}
return null;

}


private static ListItem GetDocumentFromSP(string documentName)
{

//This method is discussed above i.e. Get List Item Collection from SharePoint
//Document List
ListItemCollection listItems = GetListItemCollectionFromSP("FileLeafRef", 
    documentName, "Text", 1);


return (listItems != null && listItems.Count == 1) ? listItems[0] : null;

}
  • Please don't post duplicate answers, try to specify each answer. Thank you! – Benny Skogberg Sep 30 '14 at 5:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.