CSVファイルをポップアップウィンドウに出力しようとしています。メインウィンドウでCSVを出力できますが、ポップアップでは出力できません。 私は同じコードを使用します。例えば;私はフォームを使用してCSVファイルを出力します。このフォームがメインウィンドウの場合、CSVファイルを出力できます。このフォームをポップアップとして使用すると出力できません。どのようにできるのか?ASP.NetのC#を使用してポップアップウィンドウのCSVファイルを出力する
それは私のCSV出力機能である:
public void OutputCSV(DataTable dtValue, string strFilename)
{
if (TextUtility.IsNullOrEmpty(strFilename))
{
throw new I01Exception(Enums.ExType.System, "9909_35");
}
DataTable dt = dtValue;
StringBuilder sb = new System.Text.StringBuilder();
string strCh = ",";
//項目名
for (int k = 0; k < dt.Columns.Count; k++)
{
sb.Append("\"" + dt.Columns[k].Caption + "\"" + strCh);
}
sb.Remove(sb.Length - 1, 1);
//データ
foreach (DataRow row in dt.Rows)
{
sb.AppendLine(string.Empty);
for (int i = 0; i < dt.Columns.Count; i++)
{
sb.Append("\"" + row[i].ToString() + "\"" + strCh);
}
}
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.AppendHeader("content-disposition", string.Format("attachment; filename={0}", HttpUtility.UrlEncode(strFilename + ".csv")));
HttpContext.Current.Response.ContentType = "text/comma-separated-values";
HttpContext.Current.Response.ContentEncoding = Encoding.GetEncoding("shift-jis");
HttpContext.Current.Response.Write(sb.ToString());
HttpContext.Current.Response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();
HttpContext.Current.Response.End();
}
「ポップアップ」を定義し、CSVを出力した方法を表示します。 –
コードを表示してください。どのようにCSVファイルを表示するには? –
"text/csv"をMIMEタイプ(Response.ContentType)として使用してみてください。 "text/comma-separated-values"のRFCを見つけることができません(RFC 4180はtext/csv:http://tools.ietf.org/html/rfc4180です) –