没有更多的回发在SharePoint文件下载后 [英] No more post back after file download in sharepoint
问题描述
我试图从SharePoint下载文件。
但我下载此文件后,我不能点击其他按钮。
什么是错我的编码?
这是我的第一个方法。
Response.AppendHeader(内容处置,附件;文件名=+文件名);
Response.ContentType =text / plain的;
Response.WriteFile(使用Server.Mappath(〜/+文件名));
到Response.End();
块引用>这是我的第二个办法
字节[]字节= System.IO.File.ReadAllBytes(D:\\\\+文件名); Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader(内容类型,应用程序/八位字节流);
Response.AddHeader(内容长度,bytes.Length.ToString()); Response.AddHeader(内容处置,附件;文件名=+文件名); Response.BinaryWrite(字节);
Response.Flush();
到Response.End();
块引用>我甚至评论到Response.End(),但仍是同样的结果。
有没有我应该尝试任何其他方式?
任何帮助将是非常美联社preciated。
其实,我前几天发布了这个问题,但只有一个给了我第二次尝试我的方式,但它仍然没有工作。感谢。
更新
下面是我在GridView控件GridView控件。
< ASP:GridView控件ID =gvGiroWIDTH =100%=服务器网格=两者AllowPaging =假的CssClass =形表 ShowHeader =假
AllowSorting =假的AutoGenerateColumns =假OnRowDataBound =gvGiro_RowDataBound>
<柱体和GT;
< ASP:的TemplateField ItemStyle-WIDTH =20%ItemStyle-HorizontalAlign =中心>
<&ItemTemplate中GT;
< ASP:标签ID =lblValueDate文本='<%#GETDATE(EVAL(ValueDate))%GT;' =服务器/>
< / ItemTemplate中>
< / ASP:的TemplateField>
< ASP:的TemplateField>
<&ItemTemplate中GT; < ASP:GridView控件ID =gvDetail=服务器AllowPaging =假AllowSorting =假
的CssClass =列表,表格边框HeaderStyle-的CssClass =头的AutoGenerateColumns =false的>
<柱体和GT;
< ASP:的TemplateField的HeaderText =序列号ItemStyle-HorizontalAlign =左
ItemStyle宽度=30%>
<&ItemTemplate中GT;
<%#((DataRowView的)的Container.DataItem)[MessageSeqNbr]%GT;
< / ItemTemplate中>
< / ASP:的TemplateField>
< ASP:的TemplateField的HeaderText =借方交易总数ItemStyle-HorizontalAlign =左
HeaderStyle-HorizontalAlign =中心>
<&ItemTemplate中GT;
<%#((DataRowView的)的Container.DataItem)[TotalDebitNbr]%GT;
< / ItemTemplate中>
< / ASP:的TemplateField>
< ASP:的TemplateField的HeaderText =状态ItemStyle-HorizontalAlign =左ItemStyle-WIDTH =25%
HeaderStyle-HorizontalAlign =中心>
<&ItemTemplate中GT;
<%#((DataRowView的)的Container.DataItem)[codeDesc]%GT;
< ASP:HiddenField ID =藏code=服务器值='<%#((DataRowView的)的Container.DataItem)[code]%GT;' />
< / ItemTemplate中>
< / ASP:的TemplateField>
< ASP:的TemplateField的HeaderText =行动ItemStyle-HorizontalAlign =中心ItemStyle-WIDTH =10%
HeaderStyle-HorizontalAlign =中心>
<&ItemTemplate中GT;
< ASP:按钮的ID =btnDownload=服务器的CssClass =按钮提交文本=下载
的CommandName =下载按需=onCmdCommandArgument ='<%#的eval(ID)%GT;' WIDTH =80px/>
< ASP:按钮的ID =btnUnbatch=服务器的CssClass =按钮通用的文本=非批量
的CommandName =unbatch按需=onCmdCommandArgument ='<%#的eval(ID)%GT;' WIDTH =80px/>
< / ItemTemplate中>
< / ASP:的TemplateField>
< /专栏>
< / ASP:GridView的>
< / ItemTemplate中>
< / ASP:的TemplateField>
< /专栏>
< / ASP:GridView的>下面是我的CS文件
保护无效gvGiro_RowDataBound(对象发件人,GridViewRowEventArgs E)
{
GridView控件克;
如果(e.Row.RowType == DataControlRowType.DataRow)
{
GR =(GridView控件)e.Row.FindControl(gvDetail);
使用(等级2 CT2 =新的Class2())
{
标签lblValueDate =(标签)e.Row.FindControl(lblValueDate);
DateTime的DT = DateTime.MinValue;
DataSet的DS = ct2.GetData(DT);
gr.DataSource = DS;
gr.DataBind(); } }
}
保护无效onCmd(对象发件人,CommandEventArgs E)
{
字符串ID;
开关(e.CommandName)
{
案unbatch:
ID = e.CommandArgument.ToString();
Unbatch(ID);
打破;
案下载:
ID = e.CommandArgument.ToString();
下载(ID);
打破;
默认:
打破;
}
} 保护无效下载(字符串ID)
{
//做 - 代替所有硬件code GUID
GUID batchId =新的GUID(ID);
字符串文件名=;
1级克拉=新1级();
{
如果(!ct.FileExists(batchId,参考文件名))
{
字节[]字节= System.IO.File.ReadAllBytes(D:\\\\+文件名);
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader(内容类型,应用程序/八位字节流);
Response.AddHeader(内容长度,bytes.Length.ToString());
Response.AddHeader(内容处置,附件;文件名=+文件名);
Response.BinaryWrite(字节);
Response.Flush();
到Response.End();
}
关于提交处理解决方案的SharePoint注册一个JavaScript。在此处理程序的全局变量
_spFormOnSubmitCalled
设置为真正
。 SharePoint使用这个变量来检查,如果一个提交被执行和prevents任何进一步的提交。因为你的下载回发并不刷新页面这个变量保持真正
。有了效果,所有其他按钮停止工作。作为一种替代方法您可以将此变量在客户端单击处理程序上的下载按钮设置为false:
按钮BTN =新按钮();
btn.Text =下载;
btn.Click + = DownloadButton_Click;//设置客户端点击处理程序
btn.OnClientClick =window.setTimeout(函数(){_spFormOnSubmitCalled = FALSE;},10);当然,这就是一个小哈克,不garantueed在即将到来的版本的SharePoint工作。
I tried to download a file from sharepoint. But after I download this file, I can't click on other buttons. What is wrong with my coding?
This is my first way.
Response.AppendHeader("content-disposition", "attachment; filename= " + fileName); Response.ContentType = "text/plain"; Response.WriteFile(Server.MapPath("~/" + fileName)); Response.End();
This is my second way
byte[] bytes = System.IO.File.ReadAllBytes("D:\\" + fileName); Response.ClearContent(); Response.ClearHeaders(); Response.AddHeader("Content-Type", "application/octet-stream"); Response.AddHeader("Content-Length", bytes.Length.ToString()); Response.AddHeader("content-disposition", "attachment; filename= " + fileName); Response.BinaryWrite(bytes); Response.Flush(); Response.End();
I even comment Response.End() but still the same result.
Is there any other way I should tried?
Any help would be really appreciated. In fact, I posted this question a few days ago, but only one gave me my second way to try but it is still not working.
Thanks.
UPDATE
Here is my GridView under GridView.
<asp:GridView ID="gvGiro" Width="100%" runat="server" GridLines="Both" AllowPaging="false" CssClass="form-table" ShowHeader="false" AllowSorting="false" AutoGenerateColumns="false" OnRowDataBound="gvGiro_RowDataBound"> <Columns> <asp:TemplateField ItemStyle-Width="20%" ItemStyle-HorizontalAlign="Center"> <ItemTemplate> <asp:Label ID="lblValueDate" Text='<%# getDate(Eval("ValueDate")) %>' runat="server" /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField> <ItemTemplate> <asp:GridView ID="gvDetail" runat="server" AllowPaging="false" AllowSorting="false" CssClass="list-table border" HeaderStyle-CssClass="header" AutoGenerateColumns="false"> <Columns> <asp:TemplateField HeaderText="Sequence Number" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="30%" > <ItemTemplate> <%#((DataRowView)Container.DataItem)["MessageSeqNbr"] %> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Total Number of Debit Transaction" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Center"> <ItemTemplate> <%#((DataRowView)Container.DataItem)["TotalDebitNbr"] %> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Status" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="25%" HeaderStyle-HorizontalAlign="Center"> <ItemTemplate> <%#((DataRowView)Container.DataItem)["CodeDesc"] %> <asp:HiddenField ID="hidCode" runat="server" Value='<%#((DataRowView)Container.DataItem)["Code"] %>' /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Action" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="10%" HeaderStyle-HorizontalAlign="Center"> <ItemTemplate> <asp:Button ID="btnDownload" runat="server" CssClass="button submit" Text="Download" CommandName="download" OnCommand="onCmd" CommandArgument='<%#Eval("Id") %>' Width="80px"/> <asp:Button ID="btnUnbatch" runat="server" CssClass="button generic" Text="Un-Batch" CommandName="unbatch" OnCommand="onCmd" CommandArgument='<%#Eval("Id") %>' Width="80px"/> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
Here is my cs file
protected void gvGiro_RowDataBound(object sender, GridViewRowEventArgs e) { GridView gr; if (e.Row.RowType == DataControlRowType.DataRow) { gr = (GridView) e.Row.FindControl("gvDetail"); using (class2 ct2= new Class2()) { Label lblValueDate = (Label)e.Row.FindControl("lblValueDate"); DateTime dt= DateTime.MinValue; DataSet ds= ct2.GetData(dt); gr.DataSource = ds; gr.DataBind(); } } } protected void onCmd(object sender, CommandEventArgs e) { string id; switch (e.CommandName) { case "unbatch": id= e.CommandArgument.ToString(); Unbatch(id); break; case"download": id= e.CommandArgument.ToString(); Download(id); break; default: break; } } protected void Download(string id) { // to do - substitute all hard-code guid Guid batchId = new Guid(id); string fileName = ""; Class1 ct = new Class1(); { if (!ct.FileExists(batchId , ref fileName)) { byte[] bytes = System.IO.File.ReadAllBytes("D:\\" + fileName); Response.ClearContent(); Response.ClearHeaders(); Response.AddHeader("Content-Type", "application/octet-stream"); Response.AddHeader("Content-Length", bytes.Length.ToString()); Response.AddHeader("content-disposition", "attachment; filename= " + fileName); Response.BinaryWrite(bytes); Response.Flush(); Response.End(); }
解决方案SharePoint registers a JavaScript "on submit" handler. In this handler the global variable
_spFormOnSubmitCalled
is set totrue
. SharePoint uses this variable to check if a submit was executed and prevents any further submits. Since your "download postback" does not refresh the page this variable remainstrue
. With the effect that that all other buttons stop working.As a workaround you can set this variable to false in a client click handler on your download button:
Button btn = new Button(); btn.Text = "Download"; btn.Click += DownloadButton_Click; // set the client click handler btn.OnClientClick = "window.setTimeout(function() { _spFormOnSubmitCalled = false; }, 10);"
Of course thats a little hacky and is not garantueed to work in upcoming SharePoint versions.
这篇关于没有更多的回发在SharePoint文件下载后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!