If your form is hosted inn sharepoint, You can use server object model for this
If it is hosted outside, you can use client object model:
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();
}
}
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;
}