zoukankan      html  css  js  c++  java
  • DevExpress asp.net 导出Excel 自动开启迅雷问题,默认保存为aspx页面

    目前采取曲线救国策略:

    利用MVC .....

    <dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" KeyFieldName="FriendLinkID" Theme="Default" EnableTheming="True">
                    <Columns>
                        <dx:GridViewDataTextColumn FieldName="FriendLinkID" ReadOnly="True" VisibleIndex="0">
                            <EditFormSettings Visible="False" />
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn FieldName="LinkName" VisibleIndex="1">
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn FieldName="LinkSrc" VisibleIndex="2">
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn FieldName="Contact" VisibleIndex="3">
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataDateColumn FieldName="PublishData" VisibleIndex="4">
                        </dx:GridViewDataDateColumn>
                    </Columns>
                </dx:ASPxGridView>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Pengbg_DataConnectionString %>" 
                    SelectCommand="SELECT * FROM [Friendlink]"></asp:SqlDataSource>
                <dx:ASPxGridViewExporter ID="ASPxGridViewExporter1" GridViewID="ASPxGridView1" runat="server"></dx:ASPxGridViewExporter>
                <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
     protected void Button1_Click(object sender, EventArgs e)
            {
                var fileName = new Random().Next().ToString();
                var fullPath = @"C:" + fileName + ".xls";
                using (var fs = new FileStream(fullPath, FileMode.CreateNew, FileAccess.Write))
                {
                    ASPxGridViewExporter1.WriteXls(fs);
                }
                Response.Redirect("Default1?path=" + fullPath);
            }
     public class Default1Controller : Controller
        {
            //
            // GET: /Default1/
    
            public ActionResult Index(string path)
            {
                String newfileName = DateTime.Now.ToString("yyyyMMddHHmmssff");
                return File(System.IO.File.ReadAllBytes(path), "application/vnd.ms-excel", HttpUtility.UrlEncode(string.Format("{0}.xls", newfileName)));
            }
    
        }


    原理在推测、调试中。。。

  • 相关阅读:
    P4611 [COCI2011-2012#7] TRAMPOLIN
    P3119 [USACO15JAN]草鉴定Grass Cownoisseur
    P4417 [COCI2006-2007#2] STOL
    P4645 [COCI2006-2007 Contest#3] BICIKLI
    P1155 双栈排序
    P4610 [COCI2011-2012#7] KAMPANJA
    P4329 [COCI2006-2007#1] Bond
    EZOJ #227
    EZOJ #226
    p4980 polya定理
  • 原文地址:https://www.cnblogs.com/bingguang/p/4615537.html
Copyright © 2011-2022 走看看