C# - Getting "process Cannot Access File" Error When Deleting Files After Sending Email?

Feb 7, 2011

I am getting error as mentioned below:

The process cannot access file "E:TempPDFsSample.pdf" because it is being used by another process

I happen to send the pdf from email and after email is sent i need to delete the Sample.pdf file. The code that i have written doesn't work

FileInfo DeleteFileInfo = new FileInfo(directoryPath + "\" + filename + ".pdf");
if (DeleteFileInfo.Exists)
File.Delete(directoryPath + "\" + filename + ".pdf");

here directorypath is E:TempPDFs, filename is Sample


public static void SendMail(string fromAddress, string[] toAddress, string[] ccAddress, string[] bccAddress, string subject, string messageBody, bool isBodyHtml, ArrayList attachments, string host, string username, string pwd, string port)


View 1 Replies

Similar Messages:

Web Forms :: Error When Deleting PDF - File Is Used By Another Process

Jun 13, 2012

I have one gridview in that i have three columns "FileName"  "Open" and "Delte" if user Opens clicks on open Pdf file opens in new window that time if user clicks on Delete Button then its giving Error that "Process is using by Some one" ...

View 1 Replies

Configuration :: Web Confg File And File In Project For Sending Error Message Email

Jan 17, 2011

I am trying to configure my web application to send emails to my email address in case of any error . Below is my coding in the web config file, I am following example from a book cuase I AMM A nOVICE TO VISUAL STUDIO AND .NET AND C#. THE NAME OF THE BOOK IS ASP.Net E-Commerce in C#. I am not sure what to put in for the MailForm value since the book did not say could someone tell me .


In my other configuration file under the App_Code folder I have this coding Below:


View 1 Replies

Subsequent Access To File. Error - The Process Cannot Access File It Is Being Used By Another

Mar 29, 2010

I simply want to create one file and then delete it, means I want to access one file subsequently. I am getting the very familiar error as shown in title. (Process can't access the file,) I have tried using file stream and all other stuff that I found from Googling but no success so far. Does any body have small and neat solution? in short, I would like to run the following statements without any error.File.Create("C:\hsp1.txt");

File.Open("C:\hsp1.txt", FileMode.Open, FileAccess.Read, FileShare.None);

View 2 Replies

The Process Cannot Access The File / How To Fix This Error

Oct 24, 2010

I don't know why this does this on the delete.

line 289

The process cannot access the file 'D:InetPubReefJunkiesUsersillProfilePicture Thumb340x_la-rouxsmall.jpg' because it is being used by another process.

Description: An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.IOException: The process cannot access the file 'D:InetPubReefJunkiesUsersillProfilePicture Thumb340x_la-rouxsmall.jpg' because it is being used by another process.

Source Error:


View 6 Replies

Web Forms :: The Process Cannot Access The File 'c: Empmy.pdf' Because It Is Being Used By Another Process?

Apr 3, 2010

I've developed a popup email .aspx used on our intranet based web app that is auto generated with .pdf's attached. I'm developing with VS 2008 ASP.Net 3.5 C# and System.Net.Mail.MailMessage. I can create and send the email with no issues. The problem is with any attempt to open or delete the attachments I get the above error. The .pdf's a copied with the following code:

FileStream fsr = new FileStream(inFilename, FileMode.Open, FileAccess.Read, FileShare.Read);
BinaryReader reader = new BinaryReader(fsr);
byte[] bytes = new byte[fsr.Length];
reader.Read(bytes, 0, bytes.Length);
FileStream fsw = new FileStream(outFileName, FileMode.Create, FileAccess.Write, FileShare.Write);
BinaryWriter writer = new BinaryWriter(fsw);
writer.Write(bytes, 0, bytes.Length);
// clean up
writer = null;
fsw = null;
reader = null;
fsr = null;
Later after sending the email I:
mailMessage = null;
foreach (string fileName in attachments)
if (File.Exists(fileName))

The error occurs at: the File.Delete(fileName);

how I can delete or reopen these files after sending the email?

View 9 Replies

Web Forms :: Sending An Email Causes Error - Specified String Not In Email Format

Feb 12, 2010

have code on a web form -- when you hit the button "send emails", it executes this sub which reads an SQL database table and sends emails one by one -- however I get this error above -- anyway to check it and skip to the next email? Some emails in my table have name@test.co.il for example, so it seems this causes this error.


View 1 Replies

Sending .net Project Files In Email?

Sep 16, 2010

How can I send my .net project file to somebody. Which all files do I need to send?

View 7 Replies

Web Forms :: Process Cannot Access The File It Is Being Used By Another Process?

Nov 6, 2010

My code is that I want to create a log file and log it upon a new user browsing the site. However, what i did was I put in a 6 second delay and then used another browser to access the page. And it threw an Exception saying it is being used by another process which is true. So how come I set it so that, if IT is being used by another process, WAIT and retry every 500 milliseconds until it becomes free/available?

here's the code:

protected void Page_Load(object sender, EventArgs e)
{if (!IsPostBack) // if this is the first time page loads, set k to 1
{ lognewuser();


View 1 Replies

The Process Cannot Access The File 'C:inetpub' Because It Is Being Used By Another Process

Mar 28, 2011

I am having the text file which is used to track all the ip address which is available in the network and replace the content from"Reply from bytes=32 time=1ms TTL=255" to

For this task i am having 2 functions 1.runCMD() Function is used to create a file which ping all the ip address between 3 to 254 ("Reply from bytes=32 time=1ms TTL=255").

2.Another function textFileReplace() which is used to replace the text from "Reply from bytes=32 time=1ms TTL=255" to

This process will continue every 30 minutes..

But i am having the error while accessing the function textFileReplace() as The process cannot access the file 'C:inetpub' because it is being used by another process.

View 4 Replies

VS 2008 - Sending Email Reading All ID From Excel Files

Oct 5, 2012

I want to send the email through asp.net where "To " email address list store in excel file. Send email to all email Id store in excel file. How to send the email reading all email id from excel files.

View 1 Replies

While Trying To Download A File : The Process Cannot Access The File Because It Is Being Used By Another Process

Oct 17, 2010

I am trying to download a file from the server but i am getting this error:

The process cannot access xxxx the file because it is being used by another process

This is my CODE:
string fileName="DownLoadFiles";
string filePath = hid_filepath.Value;
FileInfo file = new FileInfo(filePath);
System.Net.WebClient wc = new System.Net.WebClient();
wc.DownloadFile(new Uri(fileName, filePath);

Foe ur Information:the file is not opened or not used.

View 1 Replies

Process Can't Access File - Used By Another Process

Feb 10, 2010

When I delete all files from the directory path. then it will give me this error The process cannot access the file because it is being used by another process. How to solve this?

View 10 Replies

C# - The Process Cannot Access The File Because It Is Being Used By Another Process

May 12, 2010

I have an asp.net website and I allready did .Dispose() here is my code below;

MailMessage newMail = new MailMessage(MailFrom, MailTo,
MailSubject, MailMsg);
if (MailAttachment != "")
Attachment data = new Attachment(MailAttachment,
newMail.BodyEncoding = System.Text.Encoding.UTF8;
newMail.IsBodyHtml = true;
SmtpClient client = new SmtpClient("");
client.Credentials = CredentialCache.DefaultNetworkCredentials;
lblSuccess.Text = "Başvurunuz alınmıştır teşekkürler.";
lblSuccess.Visible = true;
catch (Exception ex)
lblSuccess.Text = ex.Message;
//lblSuccess.Text = "Bir sorun oluştu bir daha deneyiniz.";
lblSuccess.Visible = true;

But i' m getting the same error, it' s running fine in my localhost but in server i' m getting this error. How can i fix it?

View 2 Replies

C# - The Process Cannot Access The File Because It Is Being Used By Another Process?

Feb 8, 2010

I am getting binary data from a SQL Server database field and am creating a document locally in a directory my application has permissions. However I am still getting the error specified in the title. I have tried numerous suggestions posted on the web including those suggested in previous posts on Stackoverflow. I have also used ProcessExplorer > Find Handle to locate the lock and it returns nothing as if the file is not locked.

I am using the code below to save the file to the file system and I then try to copy this file to a new location later in the application process within another method. It is this copy method that takes the path of the newly created file that throws the exception.

The file itself is created with its content and i can open it through Windows Explorer without any problems.

Am I missing something completely obvious? Am I creating the file correctly from the database?

// Get file from DB
FileStream fs = new FileStream(
"C:myTempDirectorymyFile.doc", FileMode.OpenOrCreate, FileAccess.Write);
BinaryWriter br = new BinaryWriter(fs);
// Copy file
File.Copy(sourceFileName, destinationFilename, true);

View 7 Replies

The Process Cannot Access The File Because It Is Being Used By Another Process?

Oct 5, 2010

Iam getting the above said error while Iam copying a file of relativelly Heavy say 130 MB.Below is the code which is giving the error.

System.IO.FileInfo FileInfo1 = new System.IO.FileInfo(filename1);

View 6 Replies

Process Cannot Access File Because It Is Being Used By Another Process

Feb 6, 2012

I am using a AsyncUpload(telerik), i am in a point where i am supposed to save the File to a certain Folder. First I check if the directory exist

Dim baseDire As String = Server.MapPath("~/MyFILES/")
If IO.Directory.Exists(baseDire & Request("Req_ID").ToString()) = False Then
IO.Directory.CreateDirectory(baseDire & Request("Req_ID").ToString())
End If

Because i am doing multiple Upload , i will have to loop through the items of the Upload control and save to a folder.

For Each file As UploadedFile In UploadPropDoc.UploadedFiles
Dim bytes(file.ContentLength - 1) As Byte
file.InputStream.Read(bytes, 0, file.ContentLength)
'Save the File to the disk
file.SaveAs(baseDire + file.GetName())

Now when ever i debug this , when it comes to this line

file.SaveAs(baseDire + file.GetName())

I get an Error

The process cannot access the file because it is being used by another process.

I have removed the Readonly in the Folder that it supposed to write to and gave everyone permission , but still the error persist.

View 1 Replies

How To Use Server,Xml,email Error Log Store Process On Elmah

Jun 14, 2010

using elmah i can save error log on database,email,xml .They are individually works well .I want to work in together.Suppose in my config file i can can active server log than i can not active xml log but i want to work on both .How to do.

<!-- Change this to 1 to allow remote access. If you do, be sure to lock down the elmah.axd file! -->
<security allowRemoteAccess="1" />


if i cative server log on tag it's work well than i need to deactivate rest of log storage process like : xml,mail-notification etc.If i active Xml log than it's work well than i need to deactivate rest of them .But if i active both of them then it does not work**.I want they active on same time.How to active them in the same time.if i active **mail log it does not work .I don't know why it's not work.**1) How to active Server log and Xml log on same time.2) How to active email log with 1) and individually why it's not work?** I want error log will save on database, save on specified folder as xml formate, and also want to send email notification how to active them in the same time.

View 1 Replies

Web Forms :: Email Attachement -file Is Being Used By Another Process?

Oct 28, 2010

I have a code that sends email using smtp server. There is an attachement file called test.pdf. the code is like this. This code is called from button Click event.


View 6 Replies

Web Forms :: Error In Sending Email Using .NET

Jan 5, 2010

I'm getting this error when i trying to send Email using ASP.NEt.Please Give some Solutions for this,

< objEmail.To =
Sub btnSubmit_Click(sender
object, e
as EventArgs)Dim
objEmail as
New MailMessage()"contact@abc.com"

View 12 Replies

Email Sending Gives Alert With Error

Sep 23, 2010

I have a problem with this link: [URL] I am just trying a simple email sending which should give an alert with an error if error ocurres or a sent message if it was successfull but it's not doing anyting! it's just refreshin the page with a new funny style!here is the code I am using


View 6 Replies

Error Sending Email On Asp.net From Hosted Server

Jan 19, 2011

I receiving an error when sending email from an asp.net page on a hosted server. Below is the code and error;

MailAddress from = new MailAddress("email@home.com");
MailAddress to = new MailAddress('ToMe@something.com");
using (MailMessage message = new MailMessage(from,to))
message.Subject = "Something";
message.Body = "Something is the body";

View 2 Replies

Configuration :: Sending Email & IIS 7 Permissions Error?

Aug 21, 2010

I'm trying to send an email. My code is fine, but I'm getting a permissions error:

This is a server I'm administering myself, so I have access to the IIS 7 panel. The trouble is I don't know what to set to get mail working. Anyone got any experience of this?

My permissions error:

Access to the path 'c:7c5658db-d4cd-40cf-a686-6e9630e287f9.eml' is denied.

Description: An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Access to the path 'c:7c5658db-d4cd-40cf-a686-6e9630e287f9.eml' is denied.

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access._______________________________

View 5 Replies

Sending Email With C# - Doesn't Work, But No Error Thrown

Mar 15, 2011

I am trying to send email from my C# application and i'm running into a little bit of trouble.I wrote the function below in order to make it easier to send mail from my app, but i believe there must be a problem somewhere and I just can't see it. Perhaps it's the "Can't see the forest for the trees" scenario.

The problem occurs when I try to send email via SMTP. The page just seems to time out, with no error message, at all.. LocalPickup works, as does specifying a pickup directory, but in this instance I need to use SMTP.In this case, my website is located on my home development server (running windows server 2003) and my SMTP server is a remote dedicated box running CentOS Linux with Qmail.

I've included the function I wrote, and just to answer any questions.. Yes, the SMTP port on this server is definately 26 ;)

/// <summary>
/// Sends an email
/// </summary> [code]...

View 6 Replies

MVC :: Error Sending Email To Multi Mail Addresses

Aug 2, 2010

I'm using this code for sending mail message for invite a friend, And I'm getting this error that I do not understand why Value cannot be null. Parameter name: from (I do have a from parameter as far as I understand )


View 4 Replies

Copyrights 2005-15 www.BigResource.com, All rights reserved