我有一个使用streamwriter的导出页面:
string _exportfilename = "RMAExportCustom.csv";
string _exportpath = @"C:\" + _exportfilename;
string line = "[REASON]^[OSD]^[ORDERID]^[ITEMS]^[NOTES]^[SHIPPER]^[DOW]";
//string line = "IncidentID;OrderNum;Email;Name;OriginalShipDate;Notes;ReturnTagRequired;DateRetTagGenerated;RefundRequired;RefundAmount;DateRefundIssued;InventoryItem;InventoryQuantity;eBayCredit;eBayCreditFileDate;LostValue;IncidentReturnDate;Resolved;IncidentReceived;Shipping Cost;IncidentCreatedDate;RMA;RMARequested;RestockOption;Reason;ReceivedNotes;OurShippingCost;Resolution;Shipper;Creator" + Environment.NewLine;
StreamWriter _writer = new StreamWriter(_exportpath);
DateTime date = DateTime.Now;
string cmdText = "SELECT ReasonDescription, OriginalShipDate, OrderID, STUFF((SELECT ', ' + IT.IncidentItem + ': ',IT.IncidentItemQTY FROM IncidentItems IT WHERE I.IncidentID = IT.IncidentID FOR XML PATH(''),TYPE).value('.','VARCHAR(MAX)') ,1,1,'') AS Items, Notes, ShipperName, (SELECT DATENAME(WEEKDAY, OriginalShipDate)) AS [DOW] FROM [Incidents] AS I INNER JOIN IncidentReasons Reason on I.IncidentReasonID = Reason.IncidentReasonID INNER Join ShipperID S on I.ShipperID = S.ShipperID Order By IncidentID Desc";
SqlConnection connection = new SqlConnection(CONNECTIONSTRING);
SqlCommand cmd = new SqlCommand(cmdText, connection);
SqlDataReader rdr = null;
connection.Open();
rdr = cmd.ExecuteReader();
_writer.WriteLine(line);
line = "";
while (rdr.Read())
{
line = rdr["ReasonDescription"] + "^" + rdr["OriginalShipDate"] + "^" + rdr["OrderID"] + "^" + rdr["Items"] + "^" + rdr["Notes"] + "^" + rdr["ShipperName"] + "^" + rdr["DOW"];
_writer.WriteLine(line);
line = "";
}
connection.Close();
_writer.Close();
该文件保存到c:驱动器,这可能不好,我有输出流,因此用户可以将其保存在其他地方。
this.Response.Clear();
this.Response.ContentType = "application/octet-stream";
this.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + _exportfilename + "\"");
this.Response.WriteFile(_exportpath);
this.Response.Flush();
this.Response.End();
这在两年前在Windows 7机器上工作,我允许用户整个c:驱动器上的IIS权限,但我们已经继续前进。我不认为我想去每台计算机并打开他们整个驱动器的权限。此外,整个部分保存到驱动器然后允许输出流将其保存在不同的地方不是我应该做的。
跳出橡皮筋,但最终无济于事。