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)));

        }



    }


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

你可能感兴趣的:(DevExpress)