Click here to Skip to main content
14,451,574 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello sir,

I have two codes
First code is for uploading files on the server
Second code is to replace existing file on server

I have uploaded pdf file abc.pdf on server
next time i will do reupload with same file ie, abc.pdf

string path;
      HttpPostedFile myFile = fpProposal.PostedFile;
      int nFileLen = myFile.ContentLength;
      byte[] myData = new byte[nFileLen];
      myFile.InputStream.Read(myData, 0, nFileLen);
      path = Server.MapPath("SCANNED") + "\\" +"abc.pdf";
      if (fpProposal.HasFile)

This code is working fine for uploading and replacing/overwriting existing pdf on my local machine.
but if i try same code on server.... Uploading works... but replacing/overwriting doesn't work please help me with these...this is taking too much time.
Sushil Mate 1-Jul-13 7:13am
you must be not having rights to overwrite on server, or someone is using that file.
Pheonyx 1-Jul-13 7:32am
Are you getting any exceptions being thrown? If so, what do they say?
Could it be that the system thinks the file is in use for some reason?
(use the reply feature to respond to comments so that the person who put the comment know's you have replied. I don't think you did that for your response to Sushill).
sunil mali 1-Jul-13 7:55am
No sir its not even throwing exception....
and yes i replied against sushil's comment....
sunil mali 1-Jul-13 7:56am
Sir, Read write permission is their for that folder... thats why i am able to write,
is their something called overwrite permission if yes then let me know so that i can tell my network admistrator...
Sushil Mate 1-Jul-13 8:01am
you have permission & u don't get any exception. its difficult to answer your question. can you delete the file first which you wanted to overwrite & try to rewrite.
Torakami 1-Jul-13 9:03am
you can not override .. either first check if same file exist and delete it and then create the new one .. or you can replace the existing file by attaching date at the end ... if file is exist you will append the path.extension_Date
sunil mali 1-Jul-13 9:05am
i have a situation where i have to replace my existing are telling me some solution where i can delete and create new one...
please send me code so that i can give one try....
sunil mali 1-Jul-13 9:06am
sure i will try and let u know
Torakami 2-Jul-13 1:29am
if (File.Exists(Server.MapPath(photppath)))

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100