I have an export page that uses 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();
That file is saved to the c: drive which is probably bad and I have the output stream, so the user can save it somewhere else.
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();
This worked 2 years ago on windows 7 machines and I allowed IIS permissions on the users entire c: drive but we've moved on. I don't think I want to go to every computer and open up permissions to their entire drive. Also this whole part of saving to the drive first then allowing output stream to save it somewhere different is not what I should be doing.
Hopping for a rubber ducking moment but got to the end to no avail.