So I was coding away working on a custom list item web part and I needed to the functionality to download an attachment....just the way SP in vanilla form works.
Then the unthinkable happened.......heres the original code:
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
HttpContext.Current.Response.AddHeader("content-length", fileData.Length.ToString());
HttpContext.Current.Response.BinaryWrite(fileData);
HttpContext.Current.Response.End();
I assumed that this methodology would work..after a couple of hours of bashing my head on the keyboard I finally figured out that all lists expose the attachments for a list item in the following way:
[WEBURL]/Lists/[LISTNAME]/Attachments/[LISTITEMID]/[FILENAME]
I just had to replace the square bracket items with the desired values............so why did the above method not work????? I guess Sharepoint gets screwed up when you play with the HTTPResponse object. Or so it would seem anyway.
Does anyone have any insight as to why this is?

Comments