473,473 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

FileInfo The process cannot access the file

When using FileInfo class remember fs.Close(); otherwise it holds on to
the connection
public static void LogErrorsToFile(string sException,
string sfile, string sMethod)
{
string errorlog_file = Common.GetWorkingDirectory() +
"\\errorlog.txt";
System.IO.FileInfo file = new
System.IO.FileInfo(errorlog_file);

StreamWriter swWriter = null;

if ( !file.Exists)
{
FileStream fs = file.Create();
fs.Close();
fs.Dispose();
file = null;
}

swWriter = File.AppendText(errorlog_file);
swWriter.WriteLine("===========" + DateTime.Now.ToString()
+ "===========");
swWriter.WriteLine("EXCEPTION: " + sException);
swWriter.WriteLine("FILE: " + sfile);
swWriter.WriteLine("METHOD: " + sMethod);

swWriter.WriteLine("============================== =============");
swWriter.Close();

return;
}

Oct 29 '06 #1
0 1363

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

Similar topics

2
by: David Turner | last post by:
I have created an ASP.NET page that uses the System.IO.DirectoryInfo.GetFiles() method to get a list of files in a specific directory on our web server. (I simply use this list to build some...
1
by: Antonio | last post by:
Good morning, I've the following file system : C: -> HTML -> Aziende -> Azienda_1 -> a.jpg -> Azienda_2 -> a.jpg ... -> Azienda_N -> a.jpg my desire is to create an array of fileinfo...
9
by: Paul | last post by:
Hi, VB.NET is saying the file I am creating is in use by another process and won't complete its task of moving the file to the specified destination folder. Here is my code (the main bit...
0
by: Andreas Palm | last post by:
I need to load a txt file into SQL server, so I have to use a schema.ini file. Unfortunately MS decided that in this schema.ini the name of the file that gets sucked in has to be hardcoded. So I...
1
by: Do | last post by:
Hi, I'm getting the following error messages "The process cannot access the file "c:\inetpub\wwwroot\nspi1.5\files\DSCF0009.jpg" because it is being used by another process." This happens...
1
by: Tim Failes | last post by:
This seems a trival question, but I cannot get it to work properly... Essentially my question is, how can I create a text file, and guarantee it is given the current date/time as the Creation Time?...
3
by: rn5a | last post by:
To work with files, when should one use the File class & when should one use the FileInfo class? Similarly, to work with directories, when should one use the Directory class & when should one...
6
by: fyitang | last post by:
hi guys, here is the sample: string strFileFullName = ""; try { FileInfo currentFile = GetOneFile("some directory"); strFileFullName = currentFile.FullName; // do someting...
3
by: J | last post by:
The following code finds the existing file when run in the development environment, but not when deployed (in IIS on the same box). Why? String myFile = @"J:\My_jpgs\The Den\jvc90-03.JPG";...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.