19GreenBlankets 19GreenBlankets - 27 days ago 9
C# Question

How to make 2 process access the same path?

I'm using c#. I'm receiving an error about a path is currently accessed by other processes. What my system is trying to do is to access the path: @"C:\temps\" + client_ids + "_" + rown + ".pdf" and use the same path for attachment before sending it to client's email.

here's what I've done so far. I comment out some of my code because I'm not sure what to do.

FileStream fs = null;
using (fs = new FileStream(@"C:\\temps\\" + client_ids + "_" +
rown + ".pdf",
FileMode.Open,FileAccess.Read,FileShare.ReadWrite))
{
TextReader tr = new StreamReader(fs);
//report.ExportToDisk
//(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat,tr);
//report.Dispose();
//Attachment files = new Attachment(tr);
//Mailmsg.Attachments.Add(files);
//Clients.Send(Mailmsg);
}

Ali Ali
Answer Source

you can make temp copy of file before you use it in mail attachment and then use the copy instead of the original file