.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Reg fileupload control

Posted By: Dhivakaran     Posted Date: November 02, 2010    Points:2   Category :ASP.Net
Hi

fileupload control always thows null exception error hough we have selected any files.

I have used both asp.net file upload control as well htlm file type contorl.

both are not taking any file even if we selected any file it always throws null exception error



I have used below codes

html code

<INPUT type=file id=File1 name=File1 runat="server" />

.CS code

if ((this.File1.PostedFile != null) && (this.File1.PostedFile.ContentLength > 0))
{
string fn = System.IO.Path.GetFileName(this.File1.PostedFile.FileName);
}

and have tried below code also

<asp:FileUpload ID="ImgUpload1" Width="400px" Height="22px" runat="server" />

cs code

if (Path.GetFileName(ImgUpload1.FileName.ToString()).ToString().Trim().Length > 0|| ImgUpload1.HasFile)
{
strpath = Path.GetFileName(ImgUpload1.FileName.ToString());
}
can you please any let me know the reason why its throwing null exception?


Responses
Author: Asha.MP             
Posted Date: November 02, 2010     Points: 5   

Hi..

If you are using Ajax, you can use Ajax tool AsyncronousFileUpload control,
it will be easy.

Thanks and Regards,
Asha.mp
Author: Dhivakaran             
Posted Date: November 02, 2010     Points: 5   

Hi Asha,

Can you please give some sample code about AsyncronousFileUpload

how we can upload ...

-
Dhivakaran T
Author: Dhivakaran             
Posted Date: November 02, 2010     Points: 5   

Hi Asha,

Can you please give some sample code about AsyncronousFileUpload

how we can upload ...

-
Dhivakaran T
Author: Dhivakaran             
Posted Date: November 02, 2010     Points: 5   

Hi Asha,

Can you please give some sample code about AsyncronousFileUpload

how we can upload ...

-
Dhivakaran T
Author: Asha.MP             
Posted Date: November 02, 2010     Points: 5   

Hi..

To use ajax controls you need to add reference to the ajaxtoolkit,and register that assemply in your page.
This is in aspx page to upload the file,
<Ajx:AsyncFileUpload ID="AsyncFup" runat="server" />
And in the code behind

Private Sub AsyncFup_UploadedComplete(ByVal sender As Object, ByVal e As AjaxControlToolkit.AsyncFileUploadEventArgs) Handles AsyncFup.UploadedComplete
Dim file As String = Me.AsyncFup.FileName
Dim filePath As String = DirectCast(DirectCast(sender, AjaxControlToolkit.AsyncFileUpload).PostedFile, System.Web.HttpPostedFile).FileName
End Sub


file-->Filename
filePath -->File path

Please try this..

Thanks and Regards,
Asha.mp


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend