本文介绍了在asp.net中添加动态文件上传控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我使用下面的代码进行动态文件上传 我在本地机器上工作。但是当它在服务器上更新时它无法正常工作 文件上传控制被罚款但myfileupload.HasFile返回下降 请帮助解决它I have use below code for dynamically file uploadI work at local machine. but when it update on server it is not workingfile upload control fined but myfileupload.HasFile return fallsPlease help to solve itPublic Sub LoadAttributeSub() Dim TableWidth As Unit = New Unit(100, UnitType.Percentage) Dim CellWidth As Unit = New Unit(30, UnitType.Percentage) objList = New List(Of CAttributeMaster) objDB = New DBAttributerMaster Try objList = objDB.Attribute_Sub_SELECT() Dim tblTextBox As New Table() tblTextBox.ID = "tbl" tblTextBox.Width = TableWidth For Each item In objList Dim tr As New TableRow() Dim tc As New TableCell() Dim tc1 As New TableCell() Dim lbl As New Label Dim txt As New TextBox Dim hdn As New HiddenField Dim dvImage As HtmlGenericControl = New HtmlGenericControl("div") ' Dim fileupload As New FileUpload Dim rfv = New RequiredFieldValidator lbl.Text = item.Attribute_Sub_Name lbl.ID = "lbl" & item.Attribute_Sub_Name tc.Controls.Add(lbl) tc.Width = CellWidth tr.Cells.Add(tc) Select Case item.Attribute_Sub_Type Case "Text" Case "Image" Dim fup As New FileUpload fup.ID = "img" + item.Attribute_Sub_Name fup.Attributes.Add("runat", "Server") fup.CssClass = "unwatermarked" End Select hdn.ID = "hdn" & item.Attribute_SubID hdn.Value = item.Attribute_SubID tc1.Controls.Add(hdn) tr.Cells.Add(tc1) tblattribute.Rows.Add(tr) Next pnlMasterTextBox.Controls.Add(tblattribute) Catch ex As Exception Throw ex End Try End SubProtected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click Try Dim Attribute_Sub_value = String.Empty Dim Attribute_SubID = Nothing Dim Attribute_Sub_valueID As Integer = Nothing objList = New List(Of CAttributeMaster) objDB = New DBAttributerMaster objList = objDB.Attribute_Sub_SELECT() For Each item In objList If (item.Attribute_Sub_Type = "Image") Then Dim myfileupload As FileUpload = New FileUpload myfileupload = DirectCast(Me.pnlMasterTextBox.FindControl("img" & item.Attribute_Sub_Name), FileUpload) lblchekfilename.Text = myfileupload.ToString() If myfileupload.HasFile = True Then Dim filename As String = Path.GetFileName(myfileupload.PostedFile.FileName) myfileupload.SaveAs(Server.MapPath(Convert.ToString("~/UploadImage/") & filename)) Attribute_Sub_value = filename Attribute_SubID = RecreateControls("hdn" & item.Attribute_SubID, "HiddenField") If Attribute_Sub_value <> String.Empty Or Attribute_Sub_value <> Nothing And Attribute_SubID <> String.Empty Then Attribute_Sub_valueID = AttributeMaster_Sub_Value_INSERT(Attribute_SubID, Attribute_Sub_value) End If End If Else End If End If Next Catch ex As Exception Throw ex End Try End Sub推荐答案 这篇关于在asp.net中添加动态文件上传控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-28 07:25