Saturday, February 28, 2009

Kid's Corner in Microsoft MSDN

Are you a cool kid who wants to impress your friends and family with your mad skillz? Check out the Kid's Corner for lots of fun, easy to understand lessons on programming!

Wednesday, February 25, 2009

I was asked if I worked before on making a module to allow the users from downloading a document without the direct access to that document, the document (not just images) may be saved in SQL or on MOSS document library with no read access to the user.
Yes I worked before on file types like word files, but general files NO. and I give him the main idea of adding the document stream response and change the response content type.
And after a while I asked him about the output and he sends this code to me:

System.IO.FileInfo fileInfo = new System.IO.FileInfo(@"C:\d\AhmedCV.doc");
System.IO.FileStream fl = fileInfo.OpenRead();
byte[] file = new byte[(int)fl.Length];
fl.Read(file, 0, (int)fl.Length);
System.IO.MemoryStream mem = new System.IO.MemoryStream(file);
Response.ContentType = "application/x-unknown";
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);