Click here to Skip to main content
15,917,565 members
Home / Discussions / C#
   

C#

 
QuestionFile access is denied Pin
rkcsharp9-Aug-07 15:37
rkcsharp9-Aug-07 15:37 
AnswerRe: File access is denied Pin
Guffa9-Aug-07 15:53
Guffa9-Aug-07 15:53 
Are you closing the file properly?

If you leave the file open, it will eventually get closed when the stream object is finalized by the garbage collector. This may happen at any time, and would typically show the behaviour that you are experiencing.

Preferably you would use a using block to make sure that the file is always closed properly. Example:

using (StreamWriter writer = File.CreateText(@"c:\test.txt")) {
   writer.WriteLine("Hello world.");
}


The StreamWriter (and the underlying FileStream) will automatically be closed and disposed at the closing }.

---
single minded; short sighted; long gone;

GeneralRe: File access is denied Pin
rkcsharp9-Aug-07 16:15
rkcsharp9-Aug-07 16:15 
AnswerRe: File access is denied Pin
Luc Pattyn9-Aug-07 16:16
sitebuilderLuc Pattyn9-Aug-07 16:16 
GeneralRe: File access is denied Pin
rkcsharp9-Aug-07 16:28
rkcsharp9-Aug-07 16:28 
AnswerRe: File access is denied Pin
rkcsharp9-Aug-07 16:33
rkcsharp9-Aug-07 16:33 
AnswerRe: File access is denied Pin
Guffa9-Aug-07 17:10
Guffa9-Aug-07 17:10 
GeneralRe: File access is denied Pin
rkcsharp9-Aug-07 17:19
rkcsharp9-Aug-07 17:19 
AnswerRe: File access is denied Pin
Guffa9-Aug-07 18:10
Guffa9-Aug-07 18:10 
GeneralRe: File access is denied Pin
rkcsharp9-Aug-07 18:33
rkcsharp9-Aug-07 18:33 
AnswerRe: File access is denied Pin
Nouman Bhatti9-Aug-07 19:55
Nouman Bhatti9-Aug-07 19:55 
GeneralRe: File access is denied Pin
rkcsharp9-Aug-07 21:30
rkcsharp9-Aug-07 21:30 
AnswerRe: File access is denied Pin
Albu Marius9-Aug-07 20:27
Albu Marius9-Aug-07 20:27 
GeneralRe: File access is denied Pin
rkcsharp9-Aug-07 21:33
rkcsharp9-Aug-07 21:33 
QuestionXNA Curve Class Pin
Mike Ellison9-Aug-07 14:51
Mike Ellison9-Aug-07 14:51 
AnswerRe: XNA Curve Class Pin
Judah Gabriel Himango9-Aug-07 15:35
sponsorJudah Gabriel Himango9-Aug-07 15:35 
GeneralRe: XNA Curve Class Pin
Mike Ellison10-Aug-07 6:16
Mike Ellison10-Aug-07 6:16 
GeneralRe: XNA Curve Class Pin
Judah Gabriel Himango10-Aug-07 6:25
sponsorJudah Gabriel Himango10-Aug-07 6:25 
GeneralRe: XNA Curve Class Pin
Mike Ellison10-Aug-07 6:34
Mike Ellison10-Aug-07 6:34 
GeneralRe: XNA Curve Class Pin
Judah Gabriel Himango10-Aug-07 6:48
sponsorJudah Gabriel Himango10-Aug-07 6:48 
GeneralRe: XNA Curve Class Pin
Mike Ellison10-Aug-07 14:17
Mike Ellison10-Aug-07 14:17 
QuestionHow to resolve this FxCop warning? Pin
Scott Dorman9-Aug-07 12:32
professionalScott Dorman9-Aug-07 12:32 
AnswerRe: How to resolve this FxCop warning? Pin
Andrew Rissing9-Aug-07 12:58
Andrew Rissing9-Aug-07 12:58 
GeneralRe: How to resolve this FxCop warning? Pin
Scott Dorman9-Aug-07 13:04
professionalScott Dorman9-Aug-07 13:04 
AnswerRe: How to resolve this FxCop warning? Pin
Guffa9-Aug-07 14:01
Guffa9-Aug-07 14:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.