473,569 Members | 2,536 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unable to attach file

I have a windows service that monitors a directory for newly created files.
When one is found, an e-mail is generated and the new file is added as an
attachment. In order to avoid trying to attach the file if it is still in the
process of being written to, I'm using a routine (that I found somewhere on
this site, but can't seem to locate the thread anymore...) that checks to see
if that file can be opened using a FileStream. If it can, it is attached and
e-mailed. If it can't (i.e. it's still being written to) I wait for a second
and try again.

This code works like a charm on my local system, but when I move it to the
QA box I continuously get a "File not found" error. I've double checked that
the file exists and that everything is spelled correctly. I have a hunch that
it has something to do with the permissions that the service has in terms of
reading/writing to files. Here is the code I'm using:

int timeout = 5000;
FileStream fs;
FileInfo fi = new FileInfo("D:\\r eports\\Schedul erOutput\\TestR eport.rtf");
while(timeout > 0)
{
try
{
fs = fi.Open(FileMod e.Open, FileAccess.Read Write);
fs.Close();
break;
}
catch
{
System.Threadin g.Thread.Sleep( 1000);
timeout -= 1000;
}
}

if(timeout <= 0)
{
eventLog.WriteE ntry("Timeout.. .");
}
else
{
MailMessage m = new MailMessage();
m.From = <from e-mail>;
m.To = <to e-mail>;
m.Subject = "Test";
m.Attachments.A dd(new MailAttachment
"D:\\reports\\S chedulerOutput\ \TestReport.rtf "));
System.Web.Mail .SmtpMail.Send( m);
}

Can anybody shed any light on this? Thanks!

Brian
Jul 21 '05 #1
1 1937
Update:

Digging a little deeper, it seems that the actual point of failure is in the
creation of the FileStream object via the FileInfo.Open method. The actual
exception being thrown is an UnauthorizedAcc essException: "Access to the file
'D:\reports\Sch edulerOutput\Te stReport.rtf' is denied".

I have increased the assembly trust for the .exe, I have given the Window's
account that the service runs under full access for that directory...sti ll no
luck.

Thoughts?

"bmcelhany" wrote:
I have a windows service that monitors a directory for newly created files.
When one is found, an e-mail is generated and the new file is added as an
attachment. In order to avoid trying to attach the file if it is still in the
process of being written to, I'm using a routine (that I found somewhere on
this site, but can't seem to locate the thread anymore...) that checks to see
if that file can be opened using a FileStream. If it can, it is attached and
e-mailed. If it can't (i.e. it's still being written to) I wait for a second
and try again.

This code works like a charm on my local system, but when I move it to the
QA box I continuously get a "File not found" error. I've double checked that
the file exists and that everything is spelled correctly. I have a hunch that
it has something to do with the permissions that the service has in terms of
reading/writing to files. Here is the code I'm using:

int timeout = 5000;
FileStream fs;
FileInfo fi = new FileInfo("D:\\r eports\\Schedul erOutput\\TestR eport.rtf");
while(timeout > 0)
{
try
{
fs = fi.Open(FileMod e.Open, FileAccess.Read Write);
fs.Close();
break;
}
catch
{
System.Threadin g.Thread.Sleep( 1000);
timeout -= 1000;
}
}

if(timeout <= 0)
{
eventLog.WriteE ntry("Timeout.. .");
}
else
{
MailMessage m = new MailMessage();
m.From = <from e-mail>;
m.To = <to e-mail>;
m.Subject = "Test";
m.Attachments.A dd(new MailAttachment
"D:\\reports\\S chedulerOutput\ \TestReport.rtf "));
System.Web.Mail .SmtpMail.Send( m);
}

Can anybody shed any light on this? Thanks!

Brian

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3940
by: Jimmy | last post by:
Hi, I was trying to debug two different ASP.NET projects at the same time. But I was only able to debug one of them and I got the following error for the other one: "Unable to start debugging on the web server. A debugger is already attached." When I further checked the Output window, I noticed another error message: 'Auto-attach to...
2
4797
by: TM | last post by:
When I run an ASP.Net application I am getting the following error: "Error while trying to run project: Unable to start debugging on the web server. The project is not configured to be debugged." I checked and made sure the Machine Debug Manager is running on the server, made sure the web.comfit file has debug=true. Mine is: <compilation...
1
402
by: bmcelhany | last post by:
I have a windows service that monitors a directory for newly created files. When one is found, an e-mail is generated and the new file is added as an attachment. In order to avoid trying to attach the file if it is still in the process of being written to, I'm using a routine (that I found somewhere on this site, but can't seem to locate the...
1
2137
by: SenthilVel | last post by:
Hi I have a question when debugging dotnet code when attaching vb6.exe code to this process. i get an error like : unable to attach the process. there is no managed code running in the process. INorder to attach a process with the .NET Debugger, managed code must be running in the process before attaching.
6
6432
by: eric.goforth | last post by:
Hello, I'm calling a VB.NET 2003 dll that's registered in COM+. I've added a reference to it in a VB6 DLL that I'm calling from a Classic ASP page. Previously I was able to attach to my .NET dll and debug it. I haven't been able to do this in a while and I'm thinking that it must be because I've installed VS 2005 on my machine...
2
2046
by: prajeeshv | last post by:
Hi Everyone, Have a nice day... I've a problem in SQL Server... I've detached my database from server. But I didn't remember the location of its .mdf (database) file. Now I'm unable to attach the database. Is there any way to locate the mdf file for a detached database, so I can attach it again... Any help on this will be...
3
24227
by: weird0 | last post by:
This is the exception that I get when i create a webserivce obj and call. The error comes on the webmethod call, when it opens a connection to the db. How do I fix it? What is the solution to this? System.Web.Services.Protocols.SoapException: Server was unable to process request. ---System.Data.SqlClient.SqlException: An attempt to...
0
3131
by: DR | last post by:
Unable to start TSQL Debugging. Could not attach to SQL Server Process on 'srvname'. The RPC server is unavailable. I get this error when I try to run a SQL Server Project with a CLR stored Procedure in it. The target DB is SQL Server 2005 and im using VS 2005. I simply create a new SQL Server Project which creates a Test.sql, i then simply...
1
5593
by: ziycon | last post by:
I'm getting this error when i try to attach a DB:
0
7700
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7974
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.