码迷,mamicode.com
首页 > Web开发 > 详细

DevExpress asp.net 导出Excel 自动开启迅雷问题,默认保存为aspx页面

时间:2015-07-02 13:38:18      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:

目前采取曲线救国策略:

利用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)));
        }

    }


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

DevExpress asp.net 导出Excel 自动开启迅雷问题,默认保存为aspx页面

标签:

原文地址:http://www.cnblogs.com/bingguang/p/4615537.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!