Reputation: 43
I am trying to make a button or hyperlink to open local html file. I have tried everything but none of them are not working. have tried to use LinkButton, Button and Hyperlink. Below is the code what I have tried.
byte[] buffer = (byte[])data.GetValue(i);
File.WriteAllBytes(@"C:\test.html", buffer);
//LinkButton sysInfo = new LinkButton();
//sysInfo.Text = "Please click to see more info";
//sysInfo.CommandName = "ID";
//sysInfo.CommandArgument = id.ToString();
//sysInfo.Command += new CommandEventHandler(sysInfo_Click);
//sysInfo.Click += new EventHandler(this.sysInfo_Click);
HyperLink link = new HyperLink();
link.Target = "_blank";
link.Text = "Please click to see more information";
link.Attributes.Add("onclick", "window.open('" + ResolveUrl("file:///c:/test.html") + "');");
link.NavigateUrl = ResolveUrl("file:///c:/test.html");
fieldCl.Controls.Add(link);
//sysInfo.Click += new EventHandler(sysInfo_Click);
//sysInfo.CommandName = "ID";
//sysInfo.CommandArgument = id.ToString();
//sysInfo.Command += new CommandEventHandler(sysInfo_Click);
What I was trying to do is there are bytes for html in sql server and retrieve the bytes to create file on C: local. Then I want to open the local html file on new window.
It seems ok to retrieve bytes and create a file. But when I used the hyperlink, it does not do anything. I heard that it won't allow me to open the local file. So I have tried to use the button instead but when I used a button and create Click event, it didnt even go into the Click event.
If there is anyway to just open the file without saving, that would be great but if can't, that's fine.
Upvotes: 1
Views: 1977
Reputation: 1658
I would just get your link into a string. It would just need to be: c:\\test.html
Once you get your link into a string I would try: System.Diagnostics.Process.Start(link);
If that is not working, I would place a break in your code and grab the content of the string - paste that into your address bar and see what happens.
Upvotes: 2