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 7061517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:29:02+00:00 2026-05-28T04:29:02+00:00

UPDATE 1: Here is the full code behind from the downloaded example, unedited: using

  • 0

UPDATE 1:

Here is the full code behind from the downloaded example, unedited:

using System;
using System.IO;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        String UpPath;
        UpPath = "C:\\UploadedUserFiles";

        if (!Directory.Exists(UpPath))
        {
            Directory.CreateDirectory("C:\\UploadedUserFiles\\");
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        HttpFileCollection uploads = HttpContext.Current.Request.Files;
        for (int i = 0; i < uploads.Count; i++)
        {
            HttpPostedFile upload = file;

            if (upload.ContentLength == 0)
                continue;

            string c = System.IO.Path.GetFileName(upload.FileName); // We don't need the path, just the name.

        try
            {
            upload.SaveAs("C:\\UploadedUserFiles\\" + c);
            Span1.InnerHtml = "Upload(s) Successful.";
            }
        catch(Exception Exp)
            {
                Span1.InnerHtml = "Upload(s) FAILED.";
            }
        }
    }
}

ORIGINAL QUESTION:

I’ve just downloaded a “file uploading” example from http://www.asp.net:

Link to tutorial: http://www.asp.net/web-forms/videos/how-do-i/how-do-i-multiple-file-uploads-in-aspnet-2
Link to download: http://download.microsoft.com/download/8/6/9/869ff08a-1e39-4bab-a303-f7dcedc52427/CS-ASP-MultiFileUpload-CS.zip

and copied the files to my webserver after extracting them.

When I navigate to http://server/uploader/Default.aspx

It creates the folder in the servers c drive successfully, but on the web browser I get the following error:

Server Error in '/' Application.
--------------------------------------------------------------------------------

Compilation Error 
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS0103: The name 'file' does not exist in the current context

Source Error:



Line 29:         for (int i = 0; i < uploads.Count; i++)
Line 30:         {
Line 31:             HttpPostedFile upload = file;
Line 32: 
Line 33:             if (upload.ContentLength == 0)


Source File: c:\Inetpub\wwwroot\uploader\Default.aspx.cs    Line: 31 


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3623; ASP.NET Version:2.0.50727.3618 

Anyone know why this is happening?

  • 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-28T04:29:02+00:00Added an answer on May 28, 2026 at 4:29 am

    You are addressing an undeclared local variable file, you should be retrieving the HttpPostedFile from the uploads “Items” collection using the Item index;

    HttpPostedFile upload = uploads[i]; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATE2: Tried rendering just a quad. UPDATE: The FULL code is here. Somebody can
Replaces Question: Update multiple rows into SQL table Here's a Code Snippet to update
I'm trying to update an element in the XML document below: Here's the code:
Using LaTeX , I need to show some code snippet inside a table. Here
I am trying to insert and update data using 3 prepared statements. There are
Question: Can anyone please provide a full code example that shows how one does
UPDATE: So pretty much everyone here has told me that I just need to
Update I summarized the question and its answers here My objective is to detect
Here is my chunk of code: var update_shipping_methods = function(methods) { $(methods).each( function(i) {
Update In the wiki spirit of StackOverflow, here's an update: I spiked Joe White's

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.