Results 1 to 7 of 7

Thread: Error Uploading file to Server [RESOLVED]

  1. #1

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075

    Error Uploading file to Server [RESOLVED]

    Anyone know why I'm getting this error when I try to upload?

    "Object reference not set to an instance of an object."

    <input id="pdfUpload"
    <FORM id="_ctl0" encType="multipart/form-data" runat="server">

    If Not pdfUpload.PostedFile Is Nothing Then
    If pdfUpload.PostedFile.FileName.Trim().Length > 0 And _
    pdfUpload.PostedFile.ContentLength > 0 Then
    Const strBaseDir As String = "C:\PBSS_Uploads\"
    Dim strFilename As String = _
    Path.GetFileName(pdfUpload.PostedFile.FileName)

    pdfUpload.PostedFile.SaveAs(strBaseDir & strFilename)

    End If
    End If
    Last edited by EyeTalion; Dec 9th, 2002 at 10:00 AM.

  2. #2
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Could you attach the entire source for the upload component including the ASPX part?

    Thanks
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  3. #3

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    <body MS_POSITIONING="GridLayout">
    <FORM id="_ctl0" name="_ctl0" encType="multipart/form-data" runat="server">


    <input id="pdfUpload" style="Z-INDEX: 146; LEFT: 177px; WIDTH: 319px; POSITION: absolute; TOP: 339px; HEIGHT: 20px" type="file" size="34">&nbsp;&nbsp;


    'PDF Upload
    If Not pdfUpload.PostedFile Is Nothing Then
    If pdfUpload.PostedFile.FileName.Trim().Length > 0 And _
    pdfUpload.PostedFile.ContentLength > 0 Then
    Const strBaseDir As String = "C:\PBSS_Uploads\"
    Dim strFilename As String = _
    Path.GetFileName(pdfUpload.PostedFile.FileName)

    pdfUpload.PostedFile.SaveAs(strBaseDir & strFilename)

    End If
    End If

  4. #4

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    I created another asp.net project and I only placed a button and <input> tag on the page. I still get the same error.

    "Object reference not set to an instance of an object."

    Here's the entire program:

    Code:
    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="fileUpload.WebForm1"%>
    <%@ Import Namespace="System.IO" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    	<HEAD>
    		<title>WebForm1</title>
    		<Script language="vb" runat="server">
    	Sub UploadTime(sender as object, e as eventArgs) 
    	 'PDF Upload
            If Not pdfUpload.PostedFile Is Nothing Then
                If pdfUpload.PostedFile.FileName.Trim().Length > 0 And _
                   pdfUpload.PostedFile.ContentLength > 0 Then
                    Const strBaseDir As String = "C:\PBSS_Uploads\"
                    Dim strFilename As String = _
                    Path.GetFileName(pdfUpload.PostedFile.FileName)
    
                    pdfUpload.PostedFile.SaveAs(strBaseDir & strFilename)
    
                End If
            End If
           End Sub
    		</Script>
    		<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
    		<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
    		<meta name="vs_defaultClientScript" content="JavaScript">
    		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    	</HEAD>
    	<body MS_POSITIONING="GridLayout">
    		<form id="Form1" method="post" runat="server" enctype="multipart/form-data">
    			<asp:Button id="Button1" OnClick="uploadtime" style="Z-INDEX: 101; LEFT: 105px; POSITION: absolute; TOP: 337px" runat="server" Text="Button" Width="101px" Height="40px"></asp:Button>
    			<INPUT id="pdfUpload" style="Z-INDEX: 102; LEFT: 49px; WIDTH: 350px; POSITION: absolute; TOP: 281px; HEIGHT: 23px" type="file" size="39">
    		</form>
    	</body>
    </HTML>

  5. #5
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Looks like your input box needs runat="server" (the pdfUpload box)
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  6. #6

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    thanks rat, that was it.

    Do you know how to filter out the common dialog box, so only .pdf extensions show?

  7. #7

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    let me rephrase this, can you filter out file entensions in ASP.NET like you can in VB?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width