Hi guys, I really need some help or advise.
I have an handler that my Silverlight App uses to deliver a copy of a certain Excel file to the end user in a "Viewing mode":
public class Handler1 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string filename = context.Request.QueryString["filename"].ToString();
string path = context.Request.QueryString["path"].ToString();
context.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
using (FileStream ficheiro = File.OpenRead(context.Server.MapPath("~/" + path + filename)))
{
CopyStream(ficheiro, context.Response.OutputStream);
context.Response.OutputStream.Flush();
context.Response.OutputStream.Close();
context.Response.Flush();
context.Response.Close();
context.Response.End();
}
}
public bool IsReusable
{
get {return false;}
}
private static void CopyStream(Stream input, Stream output)
{
byte[] buffer = new byte[32768];
while (true)
{
int read = input.Read(buffer, 0, buffer.Length);
if (read <= 0)
return;
output.Write(buffer, 0, read);
}
}
}
This handler is used in the Silverlight app:
System.Windows.Browser.HtmlElement myFrame = System.Windows.Browser.HtmlPage.Document.GetElementById("ifHtmlContent");
if (myFrame != null)
{
myFrame.SetStyleAttribute("width", "0");
myFrame.SetStyleAttribute("height", "0");
myFrame.SetAttribute("src", string.Format("http://mydomain/Handler_Open.ashx?filename={0}&path={1}", FileName, Path));
myFrame.SetStyleAttribute("visibility", "hidden");
myFrame.SetStyleAttribute("left", "0");
myFrame.SetStyleAttribute("top", "0");
}
It works great if the file is closed.
I have another way to open the same Excel file in a "Editing mode" for some users with higher privileges.
No problem here either.
The problem is when one high privilege user has the file opened for editing and another low privilege user tries to open a copy of that file using the above handler. Nothing happens.
I suspect that the File.OpenRead wouldn't work on an opened file but I don't know how to work around it.
Probably my newbiness has something to do with it! :-)
Can anyone advise me on this?
Thanks