1

I have a class that needs an System.Web.HttpPostedFile object.

In most cases this is obtained when the user uploads a pic. However, in cases where they don't I need to pass a default image to the class.

But how do I populate the HttpPostedFile property if I'm not using the fileupload control?

NotMe
  • 87,343
  • 27
  • 171
  • 245
KoolMoK
  • 161
  • 1
  • 1
  • 3
  • possible duplicate of [How to instantiate a HttpPostedFile](http://stackoverflow.com/questions/5514715/how-to-instantiate-a-httppostedfile) – NotMe Jun 24 '11 at 21:34

1 Answers1

0

You cannot select a file from the users machine for them. The ONLY way for a file to be selected and transferred from a client computer to your web app is if you use the input type="file" tag (which is what the file control wraps) and let THEM select a file.

What you CAN do is detect on post back whether they transferred a file to you or not. If they haven't then you can use a file local to the SERVER to use instead; however, this isn't going to come through the posted file area.

As far as reasons why not: security, plain and simple.

NotMe
  • 87,343
  • 27
  • 171
  • 245
  • I believe your second paragraph is what OP was looking to do. My interpretation of the question is that he wants to simulate the upload with a server side image to reuse the upload code. I give him the benefit of the doubt and believe he's not hoping that his default image is on every client machine that'll visit his site and that it's server side. – Corey Ogburn Jun 24 '11 at 19:24
  • Corey, your description is correct. I want to use a default image in the server. – KoolMoK Jun 24 '11 at 19:27
  • @KoolMok: see the comment to the original question. It has a link to code that does what you want. – NotMe Jun 24 '11 at 21:34