How to allow iPad user to use Fileupload?http://forums.asp.net/t/1652537.aspx/1?How+to+allow+iPad+user+to+use+Fileupload+Tue, 02 Aug 2011 02:06:46 -040016525374300177http://forums.asp.net/p/1652537/4300177.aspx/1?How+to+allow+iPad+user+to+use+Fileupload+How to allow iPad user to use Fileupload? <p>I'm using an image field in the EditTemplate&nbsp;of FormView to allow my users to upload an image. It works fine in all major browsers, including Safari.&nbsp; But not on the iPad. There I get the error message &quot;object reference not set to an instance of an object&quot; when the EditTemplate is submitted. </p> <p>I'm guessing it's because, on the iPad,&nbsp;the FileUpload button&nbsp;in my EditTemplate&nbsp;is &quot;greyed out&quot; (which is a problem in and of itself)...I suppose there's no built-in way for an&nbsp;iPad user (using the iPad version of Safari)&nbsp;to&nbsp;search for an image&nbsp;on the iPad hard drive to upload (without a special App, I'm guessing)....So, &nbsp;when the EditTemplate form is submitting on an iPad, I get the above error message---I think because the Fileupload field is Null (I have this theory, because the stack trace references my &quot;ValidateImage&quot; method in my code behind.)</p> <p>Anybody have any direction or answers I should try?&nbsp; Is there an obvious answer here, or should I post my EditTemplate mark-up and code behind?</p> <p>Thanks.</p> <p>&nbsp;</p> 2011-02-13T00:24:21-05:004300472http://forums.asp.net/p/1652537/4300472.aspx/1?Re+How+to+allow+iPad+user+to+use+Fileupload+Re: How to allow iPad user to use Fileupload? <p>You should add a check in your code to see if the Uploaded File is null before trying to manipulate something that might not be there in any case. As far as the IPad is concerned, you can't upload and download files from or to it. File transfer is managed by dedicated apps.<br> </p> <p>&nbsp;<br> </p> 2011-02-13T14:06:52-05:004300649http://forums.asp.net/p/1652537/4300649.aspx/1?Re+How+to+allow+iPad+user+to+use+Fileupload+Re: How to allow iPad user to use Fileupload? <pre class="prettyprint">Sub ValidateImage(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) If Session(&quot;Image&quot;) = True Then ' There is a file Dim uploadAvatar As FileUpload = DirectCast(AdvertisementForm.FindControl(&quot;uploadAvatar&quot;), FileUpload) Dim UploadFileName As String = uploadAvatar.PostedFile.FileName If UploadFileName = &quot;&quot; Then ' There is no file selected args.IsValid = True Else Dim Extension As String = UploadFileName.Substring(UploadFileName.LastIndexOf(&quot;.&quot;) &#43; 1).ToLower() ' Valid file type If Extension = &quot;jpg&quot; Or Extension = &quot;bmp&quot; Then args.IsValid = True Else ' Not valid file type args.IsValid = False End If End If Else Dim uploadAvatar As FileUpload = DirectCast(AdvertisementForm.FindControl(&quot;uploadAvatar&quot;), FileUpload) Dim UploadFileName As String = uploadAvatar.PostedFile.FileName If UploadFileName = &quot;&quot; Then ' There is no file selected args.IsValid = False Else Dim Extension As String = UploadFileName.Substring(UploadFileName.LastIndexOf(&quot;.&quot;) &#43; 1).ToLower() ' Valid file type If Extension = &quot;jpg&quot; Or Extension = &quot;bmp&quot; Then args.IsValid = True Else ' Not valid file type args.IsValid = False End If End If End If End Sub</pre> <p>&nbsp;</p> <p>Thanks Mike...Above&nbsp;is I think the method that's causing the problem. I believe&nbsp;I've got a check there for when uploadAvatar is empty...Can you find anything amiss here or that I could add to improve it?&nbsp; Thanks.<br> &nbsp;</p> 2011-02-13T19:46:00-05:004300681http://forums.asp.net/p/1652537/4300681.aspx/1?Re+How+to+allow+iPad+user+to+use+Fileupload+Re: How to allow iPad user to use Fileupload? <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Condado</h4> <span class="keyword">Dim</span><span>&nbsp;UploadFileName&nbsp;</span><span class="keyword">As</span><span>&nbsp;</span><span class="keyword">String</span><span>&nbsp;=&nbsp;uploadAvatar.PostedFile.FileName&nbsp;&nbsp;</span></blockquote> <p></p> <p>You are trying to reference a file here. If there is no file, the code will error because you cannot get a property (FileName) of an object that doesn't exist. You should use the Upload.HasFile property to check to see if anything was uploaded:</p> <p><a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.hasfile.aspx">http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.hasfile.aspx</a><br> </p> <p><br> </p> 2011-02-13T20:26:23-05:004300796http://forums.asp.net/p/1652537/4300796.aspx/1?Re+How+to+allow+iPad+user+to+use+Fileupload+Re: How to allow iPad user to use Fileupload? <p>Thanks Mike...that worked!</p> 2011-02-14T00:16:13-05:004534728http://forums.asp.net/p/1652537/4534728.aspx/1?Re+How+to+allow+iPad+user+to+use+Fileupload+Re: How to allow iPad user to use Fileupload? <p>You can upload files using native iOS application. It was discussed here:</p> <p><a href="../../../../t/1610952.aspx/1?asp&#43;net&#43;upload&#43;file&#43;not&#43;working&#43;for&#43;IPad&#43;IPhone">http://forums.asp.net/t/1610952.aspx/1?asp&#43;net&#43;upload&#43;file&#43;not&#43;working&#43;for&#43;IPad&#43;IPhone</a>&nbsp;</p> 2011-08-02T02:06:46-04:00