A week after partner update in IKIN, Semarang - I finally came back there again to help some of the technical challenge in their upcoming project. The project seems interesting for me, they will use Teleform - Verity to scan the form papers and stores the softcopy to sharepoint document library.
Here's a code that we use to store a document/file programmaticaly to windows sharepoint services document library, depending on your scenario, you can change the process of File selection from OpenFileDialog control with your database record, etc...
private void UploadFile() { if( File1.ShowDialog() == DialogResult.OK ) { string strFileName= File1.FileName; string destUrl = "http://localhost:8083/Shared Documents/tes.log";//+strFileName;
SPWeb site = new SPSite(destUrl).OpenWeb();
Stream fStream = new FileStream(File1.FileName, FileMode.Open,FileAccess.Read); byte[] contents = new byte[fStream.Length];
fStream.Read(contents, 0, (int)fStream.Length); fStream.Close(); site.Files.Add(destUrl, contents); } }
You need to add reference (Microsoft.Sharepoint.dll) for your project from C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\ISAPI , and add the following items at the beginning of your code:
using System.IO;using System.Net;using Microsoft.SharePoint;
In reality, you may want to change the "tes.log" with the real File Name that being generated / created. Here's the result of the sample code on my sharepoint services...