I have some update panels on my page that do some asyncpostbacks to keep some dropdownlists correctly populated. My problem is that on my page i have a开发者_StackOverflow中文版n HTML input that is handling some file uploads. With the AJAX on the page with asyncpostbacks, and while i step through my code behind, the files arent being uploaded. Using a postbacktrigger (non-async) is not possible because of my layout.
Here is my code:
<div id="divFileInputs" runat="server">
<input id="file1" name="fileInput" type="file" runat="server" size="50" style="width: 50em"
onfocus="AddFileInput()" class="textbox" /></div>
<select id="selectFileList" name="ListBox1" size="5" style="width: 50em; text-align: left;"
class="textbox" />
<input id="RemoveAttachmentButton" type="button" value="Remove" onclick="RemoveFileInput()"
class="removebutton " />
</div>
Here is my code behind:
Protected Sub CopyAttachments(ByVal issueId As String)
Dim files As HttpFileCollection = Request.Files
Dim myStream As System.IO.Stream
Dim service As New SubmitService.Service
For i As Integer = 0 To files.Count - 1
Dim postedFile As HttpPostedFile = files(i)
Dim fileNameWithoutPath As String = System.IO.Path.GetFileName(postedFile.FileName)
If fileNameWithoutPath.Length > 0 And issueId.Length > 0 Then
Dim fileLength As Integer = postedFile.ContentLength
Dim fileContents(fileLength) As Byte
' Read the file into the byte array. Send it to the web service.
myStream = postedFile.InputStream
myStream.Read(fileContents, 0, fileLength)
service.ClearQuestAttachToIssue(issueId, fileNameWithoutPath, fileContents)
End If
Next
service = Nothing
End Sub
When I put a breakpoint in at the declaration of service and then check the value of "files", the count is 0. I am expecting it to be 2 when i have one file uploaded.
Anyone know how to fix this?
Ok so here is the solution. The submit button that I used was attached to an AJAX asncypostback. Thus not posting back the whole page. I changed it to just a postback update panel and bingo..works!
精彩评论