Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 20th, 2006, 02:16 AM
Registered User
 
Join Date: Aug 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default file upload

hi
i'm trying to upload a file using htmlinputfile control and one server button control to retrieve the information about the file uploaded.
here i use in aspx page
<form id="Form1" method="post" runat="server" ncType="multipart/form-data">
<input type="file" id="MyFile" runat="server" >
<asp:Button id="saveimage" runat="server" Text="Upload"></asp:Button>
</form>

so in cs file i wrote
private void Upload_Click(object sender, System.EventArgs e)
        {
            try
            {
              string filename = File.PostedFile.FileName;
            int len= File.PostedFile.ContentLength;

            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message.ToString());
            }

        }

it always throw exception like
Object reference not set to an instance of an object

i couldn't get the solution.wht'll be solution for tht plz solve it.
thanx in advance

with regards
swagat


 
Old February 20th, 2006, 06:26 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

Hi Swagat

use the object name insted of the classname

Code:
string filename = MyFile.PostedFile.FileName;
int len= MyFile.PostedFile.ContentLength;

Regards
Ganesh





Similar Threads
Thread Thread Starter Forum Replies Last Post
Filter File Types in ASP.NET File Upload ramuis78 ASP.NET 2.0 Basics 2 May 31st, 2007 10:50 AM
file upload asudhakar C# 1 April 4th, 2007 07:29 AM
Whole Folder upload(Multi file Upload) ramasamy_rams XML 1 September 9th, 2005 12:43 PM
JSP file upload and delete file pandjie JSP Basics 0 January 29th, 2005 10:49 PM
Upload file hbcontract XML 2 November 6th, 2003 07:54 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.