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

  • SEARCH
  • Home
  • 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 560127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:18:37+00:00 2026-05-13T12:18:37+00:00

Im using scott hanselmans file upload code: public ActionResult UploadFiles() { var r =

  • 0

Im using scott hanselmans file upload code:

public ActionResult UploadFiles()

{
var r = new List();

  foreach (string file in Request.Files)
  {
     HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
     if (hpf.ContentLength == 0)
        continue;
     string savedFileName = Path.Combine(
        AppDomain.CurrentDomain.BaseDirectory, 
        Path.GetFileName(hpf.FileName));
     hpf.SaveAs(savedFileName);

     r.Add(new ViewDataUploadFilesResult() 
        { Name = savedFileName, 
          Length = hpf.ContentLength });
  }
  return View("UploadedFiles",r);

}

I dont want this to exist in the controller. rather call it as a static method in a utils.cs class

is this possible?

  • 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-05-13T12:18:38+00:00Added an answer on May 13, 2026 at 12:18 pm

    Yes, but you’ll need to pass your request object in to the function, as an outside library won’t have access to it.

    public void UploadFile(HttpRequestBase request) { ... }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've seen how to Fake the SessionState object in MVC using Scott Hanselmans MvcMockHelpers,
I am sending json list from my controller: public ActionResult LoadTree() { List<ListItem> list
I want to mock the User property of an HttpContext. I'm using Scott Hanselmans
We are using Scott Hansleman's suggestion for multiple web.configs from his post here .
I recently followed Scott Hansleman's instructions on setting up SSL locally using IIS Express
I am following Scott Gu's article to create a dynamic LINQ http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx He has
I have been using Entity Framework CTP with Code-First as in this tutorial by
Im trying to implement a UnitofWork pattern using this Scott Allen tutorial My current
I am currently using this simple code to try to connect to my database
I am using Scott Mitchell's textBox Characters and Words counter control, i downloaded it

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.