asp.net编写程序一个fileupload文件上传网页 10
用asp.net编写,我编写了一部分了,ProtectedSubbtnUpload_click(ByValsenderAsObject,ByValeAsEventArgs...
用asp.net编写,我编写了一部分了,
Protected Sub btnUpload_click(ByVal sender As Object, ByVal e As EventArgs) Handles btnUpload.Click
Dim Fileok As Boolean
Fileok = False
Dim path As String
path = Server.MapPath("/uploadfiles/")
If (FileUpload1.HasFile) Then
Dim fileextension As String
fileextension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower()
Dim allowedExtensions() As String
allowedExtensions = {".pdf", ".doc", ".xls", ".ppt", ".txt"}
Dim i As Integer
For i = 0 To allowedExtensions.Length - 1
If fileextension = allowedExtensions(i) Then
Fileok = True
End If
Next
End If
If Fileok = True Then
Try
FileUpload1.PostedFile.SaveAs(path + FileUpload1.FileName)
LblResult.Text = "文件上传成功"
Catch ex As Exception
LblResult.Text = "文件上传失败"
End Try
Else
LblResult.Text = "无法上传这种类型的文件"
End If
End Sub 展开
Protected Sub btnUpload_click(ByVal sender As Object, ByVal e As EventArgs) Handles btnUpload.Click
Dim Fileok As Boolean
Fileok = False
Dim path As String
path = Server.MapPath("/uploadfiles/")
If (FileUpload1.HasFile) Then
Dim fileextension As String
fileextension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower()
Dim allowedExtensions() As String
allowedExtensions = {".pdf", ".doc", ".xls", ".ppt", ".txt"}
Dim i As Integer
For i = 0 To allowedExtensions.Length - 1
If fileextension = allowedExtensions(i) Then
Fileok = True
End If
Next
End If
If Fileok = True Then
Try
FileUpload1.PostedFile.SaveAs(path + FileUpload1.FileName)
LblResult.Text = "文件上传成功"
Catch ex As Exception
LblResult.Text = "文件上传失败"
End Try
Else
LblResult.Text = "无法上传这种类型的文件"
End If
End Sub 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏10(财富值+成长值)
2015-04-07 · 知道合伙人互联网行家
关注
展开全部
上传文件,当然要保存到某个路径--即文件夹下。SaveAs 方法将使用 FileUpload 控件上载的文件的内容保存到 Web 服务器上的指定路径。要使对 SaveAs 的调用有效,ASP.NET 应用程序必须拥有服务器上相应目录的写访问权限。应用程序可以通过两种方式获得写访问权限。您可以将要保存上载文件的目录的写访问权限显式授予运行应用程序所使用的帐户。您也可以提高为 ASP.NET 应用程序授予的信任级别
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |