zoukankan      html  css  js  c++  java
  • 上传附件

    aspx:
    <ul style="list-style: none;display:none" class="boxs1">
    <li>
    <asp:Label ID="Label3" runat="server" Text="选择文件:"></asp:Label>
    </li>
    <li>
    <asp:FileUpload ID="filehtml" runat="server" Width="" Height="24px" />
    </li>
    </ul>


    cs:

    private string GetContentUrl()
    {
    string contenturl = "";
    if (this.filehtml.HasFile) //---or has the file
    //if(this.filehtml.FileName.ToString() != "")
    {

    string filename = this.filehtml.FileName;
    string strExtName = filename.Substring(filename.LastIndexOf('.'));
    if (strExtName == ".rar")
    {

    string strPathAndName = Server.MapPath("../filehtml/") + filename;
    filehtml.PostedFile.SaveAs(strPathAndName);

    string strPreFileName = filename.Substring(0, filename.LastIndexOf('.'));
    strPreFileName += ".htm";
    //解压Rar文件

    filename = "imagfile" + DateTime.Now.ToString("yyyyMMddHHmmssfffff");

    string ServerDir = @"C:Program FilesiRAR";//rar路径
    System.Diagnostics.Process Process1 = new Process();
    Process1.StartInfo.FileName = ServerDir + "\WinRAR.exe";
    Directory.CreateDirectory(Server.MapPath("../filehtml/") + filename); //创建解压文件夹
    Process1.StartInfo.Arguments = " x -inul -y " + strPathAndName + " " + Server.MapPath("../filehtml/") + filename;
    Process1.Start();//解压开始
    while (!Process1.HasExited) //等待解压的完成
    {
    }
    contenturl = Tools.GetImagePathHeader(Request.Url.AbsoluteUri) + "filehtml/" + filename + "/" + strPreFileName; ;
    }
    else
    {
    filename = "htl" + DateTime.Now.ToString("yyyyMMddHHmmssfffff") + filename.Substring(filename.LastIndexOf('.'));
    filehtml.SaveAs(Server.MapPath("../filehtml/") + filename);
    contenturl = Tools.GetImagePathHeader(Request.Url.AbsoluteUri) + "filehtml/" + filename;
    }
    }
    return contenturl;

    }

  • 相关阅读:
    php7 & lua 压测对比
    .NET CORE——Console中使用依赖注入
    EntityFramework Core 自动绑定模型映射
    月末总结与推书
    Dapper连接与事务的简单封装
    EntityFramework Core 学习扫盲
    从输入url到页面返回到底发生了什么
    [译]C#和.NET中的字符串
    利用C#迭代器的一个杨辉三角示例
    用 dotTrace 进行性能分析时,各种不同性能分析选项的含义和用途
  • 原文地址:https://www.cnblogs.com/guo970910/p/9820559.html
Copyright © 2011-2022 走看看