How do I create a link using C#? - c#

Could anyone tell me how to create a link from a LinkLabel in Visual Studio?
Say I'm trying to make the program pull up a browser window to www.google.com (in their default browser). How would I do that? I got the following from some example code I found:
HttpWebRequest head_request = (HttpWebRequest)WebRequest.Create("http://www.google.com");
head_request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0a2) Gecko/20110613 Firefox/6.0a2";
HttpWebResponse response = (HttpWebResponse)head_request.GetResponse();
But what I have doesn't do anything. If anything, it makes my browser go into a state of unresponsiveness.
I have
using System.Net;
using System.IO;
up top. Is that right? Thanks in advance!

What you can do like something below:
ProcessStartInfo sInfo = new ProcessStartInfo("http://mysite.com/");
Process.Start(sInfo);
An article about it: http://support.microsoft.com/kb/320478
Attach it to a link:
protected void hyperlink_Click(object sender, EventArgs e)
{
ProcessStartInfo sInfo = new ProcessStartInfo("http://mysite.com/");
Process.Start(sInfo);
}
Note: If you can't see it, then you should declare using System.Diagnostics; namespace.

The code below will open google.com in the default browser. You can call this code from anywhere. The click event of a button would be a good place to test it out!
Process.Start("http://google.com/");

Related

CefSharp - can't enable webgl

I'm initializing my Chromium Browser like this:
CefSettings settings = new CefSettings();
settings.CommandLineArgsDisabled = false;
settings.CefCommandLineArgs.Clear();
settings.CefCommandLineArgs.Add("enable-3d-apis", "1");
settings.CefCommandLineArgs.Add("enable-webgl-draft-extensions", "1");
settings.CefCommandLineArgs.Add("enable-gpu", "1");
settings.CefCommandLineArgs.Add("enable-webgl", "1");
Cef.Initialize(settings);
var chromeBrowser = new ChromiumWebBrowser();
chromeBrowser.Address = "http://get.webgl.org/";
targetGrid.Children.Add(chromeBrowser);
So I try a lot of commands found here but to no avail. It does load the website and it says "my browser does support webgl but it isn't enabled." I should see a cube rotating by the way which I don't see. I looked for some SO threads regarding this, one of them complaining about the speed and I copied the initialization from there (only that command line args), still no luck. I also tried turning off the disabling commands before adding these like
settings.CefCommandLineArgs.Add("disable-webgl", "0");
without success. Could someone tell me how to initialize CefSharp 55's webgl properly?
The WPF one has many issues and I ended up using WinFormsHost to host the control in WPF. Only then I have full touch support and GPU acceleration.
Here is how I did it.
private CefSharp.WinForms.ChromiumWebBrowser wb_Main;
public MainWindow()
{
var cs = new CefSharp.CefSettings();
cs.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0";
CefSharp.Cef.Initialize(cs);
InitializeComponent();
CefSharp.Cef.GetGlobalCookieManager().SetStoragePath(Directory.GetCurrentDirectory(), true);
wb_Main = new ChromiumWebBrowser("about:blank");
wfh_Main.Child = wb_Main; //WinformsHost control
}

Reflections for ReGIS graphics screen scraping in C# .NET API

I'm trying to create a windows forms application that can scrub screen information from a Reflections window. The problem is that it's an older version of reflections from back when WRQ still owned the app. Since Attachmate have taken it over, I can't find any documentation on the .net API related to this older version.
What I have so far is this:
private void button1_Click(object sender, EventArgs e)
{
openApp();
}
private void openApp()
{
// Create a new instance of Reflection.
Reflection4.Session reflection = new Reflection4.Session();
reflection.Visible = true;
}
So this is fine for opening a new Reflections window, but I want it to run the screen scrape on a window that is already open.
Below is a way to get the first active Reflection4.Session using Marshal.GetActiveObject(). I found the progid for Reflection4 using the ProgID Key website on MSDN. With that I found that the following code works:
Reflection4.Session session = (Marshal.GetActiveObject("Reflection4.Session.8") as Reflection4.Session);

How to pass data from windows application to web application?

I have a windows application and i want to open my web application from this windows application. My Windows application will generate a key and machine code after authorization and will save the key and machine code in to database among active users. Now i want to send this key to browser so that my web application can identify the user with his machine.
How can i do this?
i cannot use URL because the user will be able to copy the URL and use my web application from another machine. I must restrict it.
Is there any other way?
There are Two Ways to transfer winform data to web applications
If you want to transfer the data to IE then You can Use
1)MSHtml.dll
code
InternetExplorer TargetIE = null;
IHTMLDocument2 document = null;
//Check whether the IE is opened
foreach (InternetExplorer internetExplorer in new ShellWindows())
{
if (internetExplorer.Document is HTMLDocument)
{
TargetIE = internetExplorer;
break;
}
}
2) If you want to transfer data from winform to any web browser my personal advice to you please use selenium for this.
download the respective dll and driver for respective drivers from this site help
Code
using OpenQA.Selenium;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Chrome;
namespace WindowsFormsChrome
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// download the chrome driver
IWebDriver driver = new ChromeDriver(#"C:\Users\Downloads\chromedriver");
driver.Navigate().GoToUrl("http://www.yahoo.com");
IWebElement myField = driver.FindElement(By.Id("txtUserName"));
myField.SendKeys("UserName");
IWebElement myField = driver.FindElement(By.Id("txtPassword"));
myField.SendKeys("Password");
IWebElement myField = driver.FindElement(By.Id("btnLogin"));
myField.click()
}
}
}
this second part work for all browser yoou just replace chromeDriver class as per you want.
you can POST data using c#
http://msdn.microsoft.com/en-us/library/debx8sh9(v=vs.110).aspx
see also this post in stackoverflow
How to post data to a website
You can write an ashx handler and pass your data (or some reference to your data) from your windows application. Here is an example how this can be done :
how to call ASHX handler and getting the result back

Open Office Communicator Session from C#

I am working on a WPF application and I wish to open sip:Username#company.com links. I am able to open mailto links using the following code:
private void btnSendEmail_Click(object sender, RoutedEventArgs e)
{
try
{
string mailURL = String.Format("mailto:{0}", UserDetails.EmailAddress);
Process.Start(mailURL);
Close();
}
catch
{
// Handle exception
}
}
Although, I am unable to open sip: links in a similar way. What I am trying to achieve is to open a new chat session with a user, like I am able to do when I follow sip: links from Outlook.
Any ideas?
Edit: I ended up using the CommunicatorAPI. Messenger.InstantMessage() seems to work for me. More info here: http://msdn.microsoft.com/en-us/library/bb787232.aspx
Using Process.Start works fine on my system (with Microsoft Lync 2010, a newer version of Communicator):
void Main()
{
Process.Start("sip:username#company.com");
}
Running the above code results in a new chat window opening. The only exception is when I enter my own user name, in which it starts composing a new Outlook e-mail message to myself. What happens when you use this (maybe also try omitting the following call to Close).
You probably need to associate a program with the "sip" uri scheme. Try this: how do I create my own URL protocol? (e.g. so://...)
if you have Lync or Office Communicator installed, they should respond appropriately to the sip: uri scheme. Also, tel:, callto: etc. For reference, the full list is here.
Is this not working for you from a WPF app? Does it work for you from a basic html page?
I ended up using the CommunicatorAPI. Messenger.InstantMessage() seems to work for me. More info here: http://msdn.microsoft.com/en-us/library/bb787232.aspx
The following code probably didn't work for you because you were trying to IM yourself.
Process.Start("sip:username#company.com");

SendMessage user32dll on an internet explorer page

I have an Internet Explorer page opend on my desktop. The name of the webpage is TEST. With FindWindow() from user32.dll i can get a handler over the window. In this page I have a button called Go and I 2 textboxes called Name and Surname. How can I write in thewebpage my name and surname and than click Go programatically? THX
The normal approach to updating foreign windows (WM_SETTEXT et al) won't work because the form components within IE are not stock windows, rather they are rendered by IE itself.
To manipulate them you need to call via the DOM (or use something like WaitN).
using mshtml; //.net ref microsoft.mshtml
using SHDocVw; //com ref `microsoft internet controls` + change ref to no embed interop
int HWND = 0x001C0C10; //your IE
foreach(InternetExplorer ie in new ShellWindowsClass()) {
//find the instance
if (ie.HWND == HWND) {
//get doc
HTMLDocument doc = (HTMLDocument)ie.Document;
doc.getElementsByName("name").item(0).value = "bob";
doc.getElementsByName("surname").item(0).value = "smith";
doc.getElementsByName("go").item(0).click();
}
}
I am not sure what your asking is actually possible with Using Win32 (user32.dll), having said that
If your trying to interact with the web server then you could simply use httprequest and httpresponse class to GET and POST variables as required.
HttpWebRequest testRequest = (HttpWebRequest)WebRequest.Create("http://.....");
HttpWebResponse testResponse = (HttpWebResponse)testRequest.GetResponse();
string responseStatus = testResponse.StatusCode.ToString();
testResponse.Close();
http://msdn.microsoft.com/en-us/library/system.web.httprequest.aspx
http://msdn.microsoft.com/en-us/library/system.web.httpresponse.aspx
If your tring to test or reply a standard set of event then you may want to have a look at Fiddler
http://www.fiddler2.com/fiddler2/

Categories

Resources