Hi,
I have a discussion board webpart. My requirement is whenever an user attaches a document in discussion board, it will auto convert to pdf protected(Authentica), later when the user view his attachment it should be the protected one.
Now the problem is: Whenever a file is attached, am downloading to say eg:"C:\Processing\". (My Authentica tool will pull the documents from this folder and processed to pdf protected and that file will be located in "D:\pdf\")
If User1 is attaching a document say "Sample.doc", its downloaded to "C:\Processing\". then user 2 is attaching a document called "Test.ppt", now its triggering 2 times. its downloading sample.doc as well as test.ppt. if user 3 is attaching some document again it will download from the begining.
how to restrict this? I have written event receiver for this. Please look my below code and help where am wrong.
public override void ItemAttachmentAdding(SPItemEventProperties properties)
{
base.ItemAttachmentAdding(properties);
DownloadListAttachments(@"http://ms025:5555/sites/TeamChat/", "TestAttachments", @"C:\Processing");
}
public void DownloadListAttachments(string siteUrl, string listName, string downloadLocation)
{
string downloadItemLocation = string.Empty;
using (SPSite site = new SPSite(siteUrl))
{
using (SPWeb web = site.OpenWeb())
{
foreach (SPFolder folder in web.Folders["Lists"].SubFolders[listName].SubFolders["Attachments"].SubFolders)
{
foreach (SPFile file in folder.Files)
{
byte[] binFile = file.OpenBinary();
downloadItemLocation = downloadLocation;
if (!Directory.Exists(downloadItemLocation))
{
Directory.CreateDirectory(downloadItemLocation);
}
System.IO.FileStream fstream = System.IO.File.Create(downloadItemLocation + file.Name);
fstream.Write(binFile, 0, binFile.Length);
}
}
}
}
}