This is a migrated thread and some comments may be shown as answers.

[Solved] Object reference not set to an instance of an object.

3 Answers 309 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Joeri
Top achievements
Rank 2
Joeri asked on 15 Aug 2009, 04:54 AM

When I try to upload a file, I always get as filename "Object reference not set to an instance of an object." and I couldn't find the problem.

that's my web.config :

    <system.web> 
        <httpRuntime maxRequestLength="1024000" executionTimeout"3600" /> 
        <compilation debug="true">  
            <assemblies> 
                <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>  
                <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
                <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>  
                <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>  
            </assemblies> 
        </compilation> 
        <authentication mode="Windows"/>  
        <pages> 
            <controls> 
                <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
                <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
            </controls> 
        </pages> 
        <httpHandlers> 
            <remove verb="*" path="*.asmx"/>  
            <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
            <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
            <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>  
            <add verb="*" path="Telerik.RadUploadProgressHandler.ashx" type="Telerik.Web.UI.RadUploadProgressHandler, Telerik.Web.UI" validate="false" /> 
        </httpHandlers> 
        <httpModules> 
            <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
            <add name="RadUploadModule" type="Telerik.Web.UI.RadUploadHttpModule" /> 
        </httpModules> 
    </system.web> 
    <system.codedom> 
        <compilers> 
            <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">  
                <providerOption name="CompilerVersion" value="v3.5"/>  
                <providerOption name="WarnAsError" value="false"/>  
            </compiler> 
            <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">  
                <providerOption name="CompilerVersion" value="v3.5"/>  
                <providerOption name="OptionInfer" value="true"/>  
                <providerOption name="WarnAsError" value="false"/>  
            </compiler> 
        </compilers> 
    </system.codedom> 
    <system.webServer> 
        <validation validateIntegratedModeConfiguration="false"/>  
        <modules> 
            <remove name="ScriptModule"/>  
            <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
            <add name="RadUploadModule" preCondition="integratedMode" type="Telerik.Web.UI.RadUploadHttpModule" /> 
        </modules> 
        <handlers> 
            <remove name="WebServiceHandlerFactory-Integrated"/>  
            <remove name="ScriptHandlerFactory"/>  
            <remove name="ScriptHandlerFactoryAppServices"/>  
            <remove name="ScriptResource"/>  
            <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
            <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
            <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
            <add name="Telerik.RadUploadProgressHandler.ashx_*" path="Telerik.RadUploadProgressHandler.ashx" verb="*" type="Telerik.Web.UI.Upload.RadUploadProgressHandler, Telerik.Web.UI" preCondition="integratedMode,runtimeVersionv2.0" /> 
        </handlers> 
        <security > 
            <requestFiltering> 
                <requestLimits maxAllowedContentLength="1024000000" /> 
            </requestFiltering> 
        </security> 
    </system.webServer> 
    <runtime> 
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">  
            <dependentAssembly> 
                <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>  
                <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>  
            </dependentAssembly> 
            <dependentAssembly> 
                <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>  
                <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>  
            </dependentAssembly> 
        </assemblyBinding> 
    </runtime> 

3 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 17 Aug 2009, 03:47 PM
Hello Joeri,

Everything seems to be okay with your web config. Do you have any validation on your web-page? Perhaps the uploaded files are places in the InvalidFiles collection instead of the UploadedFiles one. How do you try to access the files? Are they correctly uploaded to the target folder? Can you paste here your aspx and codebehind code?

Sincerely yours,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Joeri
Top achievements
Rank 2
answered on 17 Aug 2009, 03:55 PM
            <h2>Uploading ZIP Files</h2> 
            <telerik:RadUpload ID="ru" runat="server" AllowedMimeTypes="application/x-compressed,application/x-zip-compressed,application/zip,multipart/x-zip,application/x-gzip,multipart/x-gzip"   
                BorderStyle="None" InputSize="50" MaxFileInputsCount="20"  TargetFolder="~/Temp" MaxFileSize="2000000000" 
                OverwriteExistingFiles="True" /> 
            <div class="clear"></div> 
            <telerik:RadProgressManager ID="rpm" runat="server" /> 
            <telerik:RadProgressArea id="rpa" runat="server" BorderStyle="None" 
                DisplayCancelButton="True" Skin="Outlook" > 
                <Localization Uploaded="Uploaded" /> 
            </telerik:RadProgressArea>                    
            <div class="hr"></div> 
            <asp:Button runat="server" id="Button1" Text="Submit" OnClick="btnSubmit_Click" style="float:right; width:125px;" /> 
            <div style="clear:both; height:20px;"></div> 


    protected void btnSubmit_Click(object sender, System.EventArgs e)  
    {  
        UploadedFile file = UploadedFile.FromHttpPostedFile(Request.Files[ru.UniqueID]);  
    } 

When I set my debug point on the line UploadedFile file = ...  then I see the error "object reference nots et to an instance of an object.
0
Genady Sergeev
Telerik team
answered on 17 Aug 2009, 04:16 PM
Hi Joeri,

You need to use RadUpload.UploadedFiles collection instead UploadedFile.FromHttpPostedFile. Example:

 
UploadedFile file = RadUpload1.UploadedFiles[0]; 
string fileName = file.GetName(); 

You can refer to this online demo as well.

Kind regards,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Upload (Obsolete)
Asked by
Joeri
Top achievements
Rank 2
Answers by
Genady Sergeev
Telerik team
Joeri
Top achievements
Rank 2
Share this question
or