将多个文件上传到server.mappath并显示网址路径 [英] Uploading multiple files to server.mappath and displaying Url path

查看:100
本文介绍了将多个文件上传到server.mappath并显示网址路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何上传文件,多个文件以及显示URL地址和多个文件必须存储在特定的文件夹中.

How to Upload files, multiple files and displaying url address and multiples files have to be store in a specific folder..

<pre lang="xml"><%@ Page Language="C#" AutoEventWireup="true" CodeFile="Multiple files.aspx.cs" Inherits="Multiple_files" %><br />
<br />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br />
<br />
<html xmlns="http://www.w3.org/1999/xhtml"><br />
<head runat="server"><br />
    <title></title><br />
</head><br />
<body><br />
    <form id="form1" runat="server"><br />
    <div><br />
        <table><br />
            <tr><br />
                <td><asp:FileUpload ID="fileupload1" runat="server" /></td><br />
<br />
            </tr><br />
            <tr><br />
                <td><asp:FileUpload ID="fileupload2" runat="server" /></td><br />
<br />
            </tr><br />
            <tr><br />
                <td><asp:FileUpload ID="fileupload3" runat="server" /></td><br />
<br />
            </tr><br />
            <tr><br />
                <td><asp:Button ID="btnuploadall" Text="Upload All" runat="server"<br />
                        onclick="btnuploadall_Click" /></td><br />
                        <td><asp:Label ID="label1" runat="server"></asp:Label></td><br />
                        <td><asp:Label ID="label2" runat="server"></asp:Label></td><br />
            </tr><br />
        </table><br />
    </div><br />
    </form><br />
</body><br />
</html></pre><br />
<pre><pre lang="msil">using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Web;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;<br />
<br />
public partial class Multiple_files : System.Web.UI.Page<br />
{<br />
    protected void Page_Load(object sender, EventArgs e)<br />
    {<br />
<br />
    }<br />
    protected void btnuploadall_Click(object sender, EventArgs e)<br />
    {<br />
      //  string serverFilePath = UpLoad();<br />
      //public string MultipleUpLoad(HttpPostedFile selectedFile,int ID,string type)<br />
     // {<br />
<br />
         string Filepath=null;<br />
       Filepath= Server.MapPath(@"~\");<br />
<br />
        HttpFileCollection uploadedFiles = Request.Files;<br />
<br />
        for (int i = 0; i < uploadedFiles.Count; i++)<br />
        {<br />
            HttpPostedFile userPostedFile = uploadedFiles[i];<br />
            UpLoad1(userPostedFile);<br />
<br />
        }<br />
<br />
    }<br />
    public string UpLoad1(HttpPostedFile fileToUpload)<br />
    {<br />
        string FilePath = null;<br />
        string Multiplefiles = null;<br />
        //string[] a = new string[1];<br />
<br />
        if (fileToUpload.FileName.Length > 0)<br />
        {<br />
            FilePath = Server.MapPath(@"~\");<br />
            try<br />
            {<br />
<br />
                string files;<br />
                string[] UR = fileToUpload.FileName.Split(''\\'');<br />
               //string s2 = (@"\" + fileToUpload.FileName.Split(''\\'')[UR.Length - 1]);<br />
               files= fileToUpload.FileName.Split(''\\'')[UR.Length - 1];<br />
               string s1 = FilePath + files;<br />
                fileToUpload.SaveAs(s1);<br />
                //fileToUpload.SaveAs(s2);<br />
                string s = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/") + files;<br />
                if (s.Length == 0)<br />
                    label1.Text += "error"+"\n";<br />
                else<br />
                    label1.Text += s+ "\n" ;<br />
<br />
                if (FilePath.Length > 0)<br />
                {<br />
                    Multiplefiles = Server.MapPath(@"~\MultipleFiles");<br />
                    string s2 = Multiplefiles+ @"\" + files;<br />
                    fileToUpload.SaveAs(s2);<br />
                   // string s2 = //Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/MultipleFiles") + files;<br />
                    if (s1.Length == 0)<br />
                        label2.Text += "Error" + "\n";<br />
                    else<br />
                        return "";//label2.Text += "Uploaded Successfully";<br />
<br />
                }<br />
             }<br />
<br />
            catch<br />
            {<br />
<br />
            }<br />
<br />
        }<br />
<br />
        return "";<br />
    }<br />
<br />
}</pre><br />
</pre>

推荐答案

我的第二个"Google it"的每日答案-
My second "Google it" answer of the day - upload multiple files asp.net[^]. most of the examples show saving files on a location on a server. You can filter the search for more specific requirements.


这篇关于将多个文件上传到server.mappath并显示网址路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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