Reputation: 4816
My asp.net web application provides functionality to download files from server (user click's a button, i build pdf file on server with itextsharp and send it to client with Response.BinaryWrite). Each file is properly named, for example 2012-00001.pdf, 2012-00002.pdf,...
The problem is, that the browser saves these files to temp directory and if the user downloads the same file again, then it gets renamed to something like 2012-00001 (1).pdf. This is a problem, because the user wants to attach the file to new mail message (from acrobat reader, foxit reader,...) and the attached document name is clearly wrong...
Is there any way to prevent this?
Edit - I wasn't clear enough. My question is: is there any way to prevent the browser to save the file into temp directory in the situation where the users selects 'Open' and not 'Save' or 'Save As'?
And thanks to everyone for telling me that a directory cannot contain two files with the same name :)
Upvotes: 1
Views: 1047
Reputation: 48600
No you cannot prevent this. You cannot have more than 1 files with same name in a folder.
This thing is very basic to computing and programming. In programming also you cannot have two classes with same name in a namespace.
Let us suppose in a world, situation like yours is acceptable. Then how will user distinguish which files is correct file? Will he go on opening all files?
What if there are more than 2 files? Say 2,10 or 50 files with same name.
Upvotes: 0
Reputation: 22646
Nope, you have absolutely no control over this.
If they're only emailing it on, perhaps you could you provide a button that generates the PDF and emails direct from the website?
Upvotes: 0
Reputation: 38005
Of course not. The browser is free to do whatever pleases him (and actually does the good job of not overwriting your file, unless you want so). It's the user's responsibility to be cautious on what file he attaches.
Upvotes: 1
Reputation: 1039588
Is there any way to prevent this?
No. The browser does that to prevent the user from accidentally overwriting an existing file with the same name and you have no control over this.
Upvotes: 7