在asp.net 4.5中发布和保存文件 [英] Post and save files in asp.net 4.5

查看:72
本文介绍了在asp.net 4.5中发布和保存文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在尝试创建一个自定义文件上载程序序列以集成到我的云存储项目中。我希望它看起来像Google云端硬盘。



我已经从fileupload控件提交了所选文件并且能够获取所有文件名但我想要保存所有文件发布到服务器的文件。



这是我的代码



Hi all, am trying to create a custom fileuploader sequence to integrate in my cloud storage project. I want it to look like that of Google Drive.

I have submitted the selected files from the fileupload control and able to get all files name but i want to save all files posted to the server.

This is my code

$("#<%=FileUpload1.ClientID %>").change(function () {<br />
                document.getElementById("form1").submit();<br />
                <%= ShowSelected() %>;<br />
            });







代码背后






Code Behind

Public Function ShowSelected() As String
        Dim totalfiles As Integer = 0

        For Each postedFile As HttpPostedFile In FileUpload1.PostedFiles
            Dim fileName As String = System.IO.Path.GetFileName(postedFile.FileName)
            Session("selected") &= "<hr>" & postedFile.FileName & "</br>"
            Session("files") &= postedFile.FileName & vbCrLf
            lblPostedFiles.Text = Session("selected").ToString
            totalfiles += 1
        Next

        progressbar2.Attributes("max") = totalfiles * 10
        ProgressValue = totalfiles / 10
        Return ""
    End Function

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim count As Integer = 0
        For Each Filename As String In Request.Files
            Dim hFile As HttpPostedFile = TryCast(Request.Files(Filename), HttpPostedFile)

            'Dim f As HttpPostedFile = Request.Files(Filename)
            hFile.SaveAs(Server.MapPath("~/Uploads/") & Filename)
            lblUploaded.Text &= "<hr>" & Filename & "</br>"
            progressbar2.Attributes("value") += ProgressValue
            count += 1
        Next
        lblMsg.Text = String.Format("{0} files have been uploaded successfully.", count)
    End Sub





我需要你的帮助继续。保存点击button1之后我得到的是FileUpload1作为一个0字节的文件



Pls i need your help to move on. after saving on click of button1 all i get is FileUpload1 as a file with 0 byte

推荐答案

(#<%= FileUpload1.ClientID%>)。 change(function(){< br />
document.getElementById(form1)。submit();< br />
<%= ShowSelected()%>;< br />
});
("#<%=FileUpload1.ClientID %>").change(function () {<br /> document.getElementById("form1").submit();<br /> <%= ShowSelected() %>;<br /> });







代码背后






Code Behind

Public Function ShowSelected() As String
        Dim totalfiles As Integer = 0

        For Each postedFile As HttpPostedFile In FileUpload1.PostedFiles
            Dim fileName As String = System.IO.Path.GetFileName(postedFile.FileName)
            Session("selected") &= "<hr>" & postedFile.FileName & "</br>"
            Session("files") &= postedFile.FileName & vbCrLf
            lblPostedFiles.Text = Session("selected").ToString
            totalfiles += 1
        Next

        progressbar2.Attributes("max") = totalfiles * 10
        ProgressValue = totalfiles / 10
        Return ""
    End Function

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim count As Integer = 0
        For Each Filename As String In Request.Files
            Dim hFile As HttpPostedFile = TryCast(Request.Files(Filename), HttpPostedFile)

            'Dim f As HttpPostedFile = Request.Files(Filename)
            hFile.SaveAs(Server.MapPath("~/Uploads/") & Filename)
            lblUploaded.Text &= "<hr>" & Filename & "</br>"
            progressbar2.Attributes("value") += ProgressValue
            count += 1
        Next
        lblMsg.Text = String.Format("{0} files have been uploaded successfully.", count)
    End Sub





我需要你的帮助继续。保存点击button1后我得到的是FileUpload1作为0字节的文件



Pls i need your help to move on. after saving on click of button1 all i get is FileUpload1 as a file with 0 byte


这篇关于在asp.net 4.5中发布和保存文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆