call explore.exe with path from aspx page - c#

I have crate a registry at user system. And i want when user click on my image button that is in my gridview. I shall call url protocol from registry and execute the Explorer.exe with path that i will assign with the image button on the grid.
I create registry that is below
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\PicPath]
#="URL: MPath Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\PicPath\shell]
[HKEY_CLASSES_ROOT\PicPath\shell\open]
[HKEY_CLASSES_ROOT\PicPath\shell\open\command]
#="\"C:\\Windows\\explorer.exe\""
the problem is that when i add
#="\"C:\\Windows\\explorer.exe\ " "%1
%1 is for parameter when i pass c:\Logs my system start to open infinite explorer in taskbar. But when i use #="\"C:\\Windows\\explorer.exe\"" its open explore perfect on client system. But i want that explorer.exe open certain path on client system.
below is my code that i try
protected void grdOrderList_RowDataBound(object sender, GridViewRowEventArgs e)
{
HtmlAnchor a = new HtmlAnchor();
a.HRef = "MPath:OpenForm " + "/root,C:\\Abc";
a.ID = "a1";
System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
img.ID = "img1";
img.Visible = true;
img.ImageUrl = #"~\images\blue_camera.png";
a.Controls.Add(img);
e.Row.Cells[0].Controls.Add(a);
}
So how can i do this . Thanks for you time

protected void grdOrderList_RowDataBound(object sender, GridViewRowEventArgs e)
{
HtmlAnchor a = new HtmlAnchor();
a.HRef = "MPath:OpenForm " + "/root,C:\\Abhishek";
a.ID = "a1";
//System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
//img.ID = "img1";
//img.Visible = true;
//img.ImageUrl = #"~\images\blue_camera.png";
var img = new ImageButton();
img.Click += new ImageClickEventHandler(img_Click);
a.Controls.Add(img);
e.Row.Cells[0].Controls.Add(a);
}
protected void img_Click(object sender, ImageClickEventArgs e)
{
System.Diagnostics.Process.Start(#"c:\blah.txt");
}

Related

Visual Studio 2010 ASP.net c# Download file for hyper link at runtime not working

I have a Visual Studio 2010 ASP.net web site using c#.
I can display all files for a specific folder location at runtime on a Web Page:-
protected void Page_Load(object sender, EventArgs e)
{
DirectoryInfo di = new DirectoryInfo(Server.MapPath("~/Downloads"));
int i = 0;
foreach (FileInfo fi in di.GetFiles())
{
HyperLink HL = new HyperLink();
HL.ID = "HyperLink" + i++;
HL.Text = fi.Name;
HL.NavigateUrl = "FileDownloads.aspx?file=" + fi.Name;
Page.Controls.Add(HL);
Page.Controls.Add(new LiteralControl("<br/>"));
}
}
The above code displays the files as a hyperlink on the Web Page but when I click on any link the page seems to refresh and not download the specific file?
Can I assign a password to the links?
Would a Android phone user experience the same behaviors as a windows web browser user?
Any examples would be welcomed.
tia
As a work around I now use LinkButtons.
First I manually placed a number of PlaceHolder controls on the web page.
On the Page Load event I then search a specific web site folder for any files.
If any file found then create a LinkButton and assign the method TransmitFile to the LinkButton Command event.
protected void Page_Load(object sender, EventArgs e)
{
DirectoryInfo di = new DirectoryInfo(Server.MapPath("~/Downloads"));
int i = 0;
foreach (FileInfo fi in di.GetFiles())
{
LinkButton LB = new LinkButton();
LB.ID = "LinkButton" + i++;
LB.Text = fi.Name;
LB.CommandName = Convert.ToString(i);
LB.Command += new CommandEventHandler(TransmitFile);
PlaceHolder ph = (PlaceHolder)Page.FindControl("PlaceHolder" + Convert.ToString(i));
if (ph != null)
{
ph.Controls.Add(LB);
}
}
}
protected void TransmitFile(object sender, CommandEventArgs e)
{
LinkButton lnk = sender as LinkButton;
var filePath = "~/Downloads/" + lnk.Text;
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + lnk.Text);
Response.TransmitFile(filePath);
Response.End();
}
For the Password side I've opted to have a login page prior to the download page.

Winform Simple Link

I use a LabelLink contorl in a WinForm.
On form load I set the desired link:
LinkLabel.Link link = new LinkLabel.Link();
link.LinkData = "http://stackoverflow.com/questions/ask";
linkLabel1.Links.Add(link);
On click :
void LinkLabel1LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(e.Link.LinkData as string);
}
The link is gray and nothing happens when I click on it.
What is missing?
Try this
LinkLabel.Link link = new LinkLabel.Link();
link.LinkData = "http://stackoverflow.com/questions/ask";
linkLabel1.Links.Add(link);
this.linkLabel1.Links[0].LinkData = "Ask a question";
linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.LinkLabel1LinkClicked‌​);
and
void LinkLabel1LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string url;
url = e.Link.LinkData.ToString();
if (!url.Contains("://"))
url = "http://" + url;
var myLink = new ProcessStartInfo(url);
Process.Start(myLink);
linkLabel1.LinkVisited = true;
}

Loading Image into Picturebox from URL

I'm programming an algorithm in C# to download an image from a website and my software automatically fills all the required fields and presses the download button. The problem is that I'm not able to load the image. The dialog box to download image on Internet Explorer is appearing, so I need to get the url of the picture after clicking the button "generate" and load it into the picture box. My code:
private void simpleButton6_Click(object sender, EventArgs e)
{
string i = "0";
HtmlElement hu = webBrowser3.Document.GetElementById("data-text");
hu.Focus();
hu.SetAttribute("Value", txtEncodeData.Text);
HtmlElement hu1 = webBrowser3.Document.GetElementById("color");
hu1.Focus();
Color c = customColorBlender1.SelectedColor;
string hex = c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2");
hu1.SetAttribute("Value", hex);
HtmlElement hu2 = webBrowser3.Document.GetElementById("effect");
hu2.Focus();
if (comboBoxEdit1.SelectedIndex == 1)
{
i = "1";
}
hu2.SetAttribute("Value", i);
webBrowser3.Document.GetElementById("generate").InvokeMember("click");
t.Interval = 1000;
t.Start();
t.Tick += new EventHandler(t_Tick);
}
void t_Tick(object sender, EventArgs e)
{
t.Stop();
String url = Convert.ToString(webBrowser3.Document.GetElementById("download").InvokeMember("click"));
MessageBox.Show(url);
pictureBox15.ImageLocation = Convert.ToString((Uri)webBrowser3.Document.GetElementById("download").InvokeMember("click"));
}

How can I update image in listview in gridview format?

how can i update image in listview in gridview formate using folder path in asp.net in c#?
protected void UpdateButton_Click(object sender, EventArgs e)
{
TextBox ApplicantIdTextBox = (TextBox)RadListView8.FindControl("ApplicantIdTextBox");
FileUpload photoTextBox = (FileUpload)RadListView8.FindControl("photoTextBox");
string fileName1 = Path.GetExtension(ApplicantIdTextBox + photoTextBox.FileName);
string fileSavePath = Server.MapPath("ImageStorage/" + fileName1);
tblPersonalInfo pi = new tblPersonalInfo();
pi.photo = fileName1;
photoTextBox.SaveAs(fileSavePath);
dbcontext.AddTotblPersonalInfoes(pi);
dbcontext.SaveChanges();
}
But it show me error...What can i do?
Server Error in '/HrPayRoll' Application.
Object reference not set to an instance of an object.
I'd rewrite it something like this and then run it in debug mode and see what line the error is on. You were trying to use applicantIdTextBox as a string, although I would have thought that would give a different error:
protected void UpdateButton_Click(object sender, EventArgs e)
{
TextBox applicantIdTextBox = RadListView8.FindControl("ApplicantIdTextBox") as TextBox;
FileUpload photoTextBox = RadListView8.FindControl("photoTextBox") as FileUpload;
if ((applicantIdTextBox != null) && (photoTextBox != null))
{
string fileName = Path.GetExtension(applicantIdTextBox.Text + photoTextBox.FileName);
string fileSavePath = Server.MapPath("ImageStorage/" + fileName);
tblPersonalInfo personalInfo = new tblPersonalInfo();
personalInfo.photo = fileName;
photoTextBox.SaveAs(fileSavePath);
dbcontext.AddTotblPersonalInfoes(personalInfo);
dbcontext.SaveChanges();
}
}

Code is not executed in server side?

The code tested and working in local computer but not in server side. So, i use log4net to see what happen, and here is what the log4net produce: http://pastebin.com/Xr3iq68t As you all can see, i put log4net almost in every line of my code.
What is the differences between my local computer with server(i'am using somee.com free hosting to test the code).
If it because of permission problem, i have tested another code which is downloading a snapshot from same source and save it in server side folder and it can save it.
So, is there anything wrong with the code?
The code executed until Rec class only, not proceed to the rest of the code. It should go to video_NewFrame after that, but from log file record, it not continue.Complete code can be viewed here: http://pastebin.com/VCjVj3uc
protected void Button1_Click(object sender, EventArgs e)
{
string usr = "http://IPaddress.com:8081/snapshot.cgi";
log.Info("DDNS: " + usr);
log.Info("Starting JPEG stream...");
//camera source
JPEGSource = new JPEGStream(usr);
log.Info("***JPEGSource = new JPEGStream(usr);***");
JPEGSource.Login = login;
JPEGSource.Password = password;
log.Info("***JPEG login & password***");
JPEGSource.Start();
log.Info("JPEGSource.Start()");
JPEGSource.NewFrame += new NewFrameEventHandler( video_NewFrame );
log.Info("***Goto video_NewFrame class***");
//System.Threading.Thread.Sleep(6000);
//Label2.Text = Label2.Text + streamingSource + "<br> ";
this.Label1.Text = "Camera Source: " + usr;
}
private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap image = (Bitmap)eventArgs.Frame.Clone();
log.Info("***Bitmap image = (Bitmap)eventArgs.Frame.Clone();***");
width = image.Width;
height = image.Height;
frames.Enqueue((Bitmap)image.Clone());
log.Info("***Cloning frame***");
if (!IsRecording)
{
log.Info("Entering thread");
IsRecording = true;
Thread th = new Thread(DoRecording);
th.Start();
}
}
Note: camera Ip address is DDNS ip address.

Categories