Click here to Skip to main content
15,879,535 members
Home / Discussions / C#
   

C#

 
AnswerRe: SMS APPLICATION Pin
Herboren11-Jul-11 5:25
Herboren11-Jul-11 5:25 
AnswerRe: SMS APPLICATION Pin
Herboren11-Jul-11 6:25
Herboren11-Jul-11 6:25 
Questionlost connection on WebService Pin
goldsoft10-Jul-11 22:29
goldsoft10-Jul-11 22:29 
AnswerRe: lost connection on WebService Pin
Dave Kreskowiak11-Jul-11 1:05
mveDave Kreskowiak11-Jul-11 1:05 
AnswerRe: lost connection on WebService Pin
DaveAuld11-Jul-11 23:05
professionalDaveAuld11-Jul-11 23:05 
QuestionDelete a File - "File does not exist" Pin
phisco12310-Jul-11 6:44
phisco12310-Jul-11 6:44 
AnswerRe: Delete a File - "File does not exist" Pin
Dr.Walt Fair, PE10-Jul-11 8:49
professionalDr.Walt Fair, PE10-Jul-11 8:49 
AnswerRe: Delete a File - "File does not exist" Pin
Heath Stewart10-Jul-11 16:15
protectorHeath Stewart10-Jul-11 16:15 
Because you have a backslash at the beginning, which means the search starts from the root of the drive. For example, if your web root is locally on the C: drive, then you're code is looking for C:\Files\whatever. I doubt that's what you want.

If your files root is under your web application root - not generally a good idea since people then have direct access at least for file extensions not configured with your server software (ex: IIS) - you can use ~ to resolve the path like so:

// Assumes you're running this from within an ASP.NET Page
string root = Server.MapPath("~/Files");
string path = Path.Combine(root, filename);
if (File.Exists(path))
{
  File.Delete(path);
}


It's also a good idea to use Path.Combine, which works on any manage host environment (though Windows is most typical) and takes care of any trailing backslashes since double backslashes in some use cases can cause problems (referencing back to root, for example).
This posting is provided "AS IS" with no warranties, and confers no rights.

Program Manager II
Visual Studio Professional Deployment Experience
Microsoft

[My Articles] [My Blog]

GeneralRe: Delete a File - "File does not exist" Pin
Ennis Ray Lynch, Jr.11-Jul-11 5:31
Ennis Ray Lynch, Jr.11-Jul-11 5:31 
GeneralRe: Delete a File - "File does not exist" Pin
Herboren11-Jul-11 5:41
Herboren11-Jul-11 5:41 
GeneralRe: Delete a File - "File does not exist" Pin
phisco12311-Jul-11 7:11
phisco12311-Jul-11 7:11 
QuestionCode Sends Me To A New Page Before Completion Pin
PDTUM10-Jul-11 4:42
PDTUM10-Jul-11 4:42 
AnswerRe: Code Sends Me To A New Page Before Completion Pin
Richard MacCutchan10-Jul-11 5:27
mveRichard MacCutchan10-Jul-11 5:27 
GeneralRe: Code Sends Me To A New Page Before Completion Pin
PDTUM11-Jul-11 4:07
PDTUM11-Jul-11 4:07 
GeneralRe: Code Sends Me To A New Page Before Completion Pin
Richard MacCutchan11-Jul-11 4:55
mveRichard MacCutchan11-Jul-11 4:55 
AnswerRe: Code Sends Me To A New Page Before Completion Pin
BobJanova10-Jul-11 22:17
BobJanova10-Jul-11 22:17 
GeneralRe: Code Sends Me To A New Page Before Completion Pin
PDTUM11-Jul-11 4:11
PDTUM11-Jul-11 4:11 
QuestionControlMessage Pin
Snow White_10-Jul-11 2:13
Snow White_10-Jul-11 2:13 
AnswerRe: ControlMessage PinPopular
Dave Kreskowiak10-Jul-11 3:44
mveDave Kreskowiak10-Jul-11 3:44 
AnswerRe: ControlMessage Pin
thatraja10-Jul-11 9:27
professionalthatraja10-Jul-11 9:27 
Questionunblock some item in form Pin
abdellah ab9-Jul-11 8:30
abdellah ab9-Jul-11 8:30 
AnswerRe: unblock some item in form Pin
Heath Stewart9-Jul-11 8:55
protectorHeath Stewart9-Jul-11 8:55 
AnswerRe: unblock some item in form Pin
DaveAuld9-Jul-11 9:05
professionalDaveAuld9-Jul-11 9:05 
AnswerRe: unblock some item in form Pin
Dr.Walt Fair, PE9-Jul-11 10:38
professionalDr.Walt Fair, PE9-Jul-11 10:38 
GeneralRe: unblock some item in form Pin
BobJanova10-Jul-11 22:19
BobJanova10-Jul-11 22:19 

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.