Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9141871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:42:10+00:00 2026-06-17T09:42:10+00:00

I have a path (stored as a string) – eg \\documents\doc1.txt . I am

  • 0

I have a path (stored as a string) – eg \\documents\doc1.txt. I am trying to initialize a variable of type HttpPostedFileBase with the file represented by the string path. How can I do that please?
I have looked at method like

 Model.File[count] = File.Open(item.PictureDirectory, FileMode.Open); 

but these return System.io.filestream objects.

FileStream file = File.OpenRead(filepath);

But how can I convert this to an httppostedfilebase?

I am trying to do exactly what is posted here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:42:10+00:00Added an answer on June 17, 2026 at 9:42 am

    Firstly, as in the other question link to, having a method that requires a HttpPostedFileBase as an input, and then requires you to send a file not automatically transferred as a HttpPostedFileBase, suggests you need to refactor the method. In the example by Pommy, perhaps an input of Stream would be more appropriate?

    Now, if you absolutely must have an instance of HttpPostedFileBase, here’s what you’re up against. The class is abstract, so you’re never going to construct it directly. Instead you’ll need to construct an inheriting class. Within the standard libraries, HttpPostedFileWrapper inherits, and takes HttpPostedFile as a constructor input.

    But here’s the rub, the constructor for HttpPostedFile is internal, so outside of the System.Web library, you’re not constructing an instance directly.

    Your options then, are:

    1. Find a factory, or some other method in System.Web that will construct a HttpPostedFile instance for you (my suspicion is you won’t find that).
    2. Implement your own inheriting class of base HttpPostedFileBase. This should be simple enough, it’s only a small class, and depending on your code making use of it, you might not even have to implement all methods.
    3. My recommended approach, if possible – Refactor your code to not use HttpPostedFileBase, and go with, say, Stream instead.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file name which is stored in a String variable path .
I have stored the XML path to items in a string like this: response->items->item
I have a directory path stored in a text file, and I need to
I have a html file stored on the server. I have the URL path
I have stored images from the net like this Documents/imagecache/domain1/original/path/inURI/foo.png Documents/imagecache/domain2/original/path/inURI/bar.png Documents/imagecache/... Documents/imagecache/... Now
I'm trying to have the user pick an audio file and store the path
I have a function and its first argument is the string with stored path
I have a list of files stored in a text file called tempfile.txt. eg
In a C program, I have a file path in a string (specifically, this
I am using labview 8.5.1 I have the path to a file stored as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.