How to attach files from local folder into sharepoint list using c# and timer job to it
Hello vetarans,1)How to attach files from local folder into sharepoint list using c# and add timer job to it.
to get files continuosly in to list.
2) i tried it but one error is "Access denied to path in sharepoint".
Make i know the exact solution for this.
Here is my Code:-
---------------------------
public void UploadFile()
{
try
{
using (SPSite oSite = new SPSite(destUrl))
{
SPWeb oWeb = oSite.OpenWeb();
SPList oList = oWeb.Lists["IncomingFax"];
foreach (FileInfo oFI in new DirectoryInfo(SelectedfilePath).GetFiles())
{
oList.EnableAttachments = true;
string destFileUrl = oList.RootFolder.ServerRelativeUrl+"/"+ oFI.Name;
oWeb.AllowUnsafeUpdates = true;
using (FileStream fileStream = new System.IO.FileStream(SelectedfilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite))
{
oWeb.Files.Add(destFileUrl, fileStream, true/*overwrite*/);
fileStream.Close();
}
}
}
}
catch (Exception ex)
{
ex.ToString();
}
}
---------------------------