How can I control IE form C#? I know that via COM you can do all sorts of interesting stuff, but looking at the SHDocVw namespace once I import the reference into my project there doesn't seem to be that many methods. For example, how would I force a button to be clicked? Or set or read the value of a specific control on a page? In general, how can I individually control an object in IE though .NET?
Here are some samples from code I've written to control IE, maybe it can help:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
//...
void SetField(WebBrowser wb, string formname, string fieldname, string fieldvalue) {
HtmlElement f = wb.Document.Forms[formname].All[fieldname];
f.SetAttribute("value", fieldvalue);
}
void SetRadio(WebBrowser wb, string formname, string fieldname, bool isChecked) {
HtmlElement f = wb.Document.Forms[formname].All[fieldname];
f.SetAttribute("checked", isChecked ? "True" : "False");
}
void SubmitForm(WebBrowser wb, string formname) {
HtmlElement f = wb.Document.Forms[formname];
f.InvokeMember("submit");
}
void ClickButtonAndWait(WebBrowser wb, string buttonname,int timeOut) {
HtmlElement f = wb.Document.All[buttonname];
webReady = false;
f.InvokeMember("click");
DateTime endTime = DateTime.Now.AddSeconds(timeOut);
bool finished = false;
while (!finished) {
if (webReady)
finished = true;
Application.DoEvents();
if (aborted)
throw new EUserAborted();
Thread.Sleep(50);
if ((timeOut != 0) && (DateTime.Now>endTime)) {
finished = true;
}
}
}
void ClickButtonAndWait(WebBrowser wb, string buttonname) {
ClickButtonAndWait(wb, buttonname, 0);
}
void Navigate(string url,int timeOut) {
webReady = false;
webBrowser1.Navigate(url);
DateTime endTime = DateTime.Now.AddSeconds(timeOut);
bool finished = false;
while (!finished) {
if (webReady)
finished = true;
Application.DoEvents();
if (aborted)
throw new EUserAborted();
Thread.Sleep(50);
if ((timeOut != 0) && (DateTime.Now > endTime)) {
finished = true;
}
}
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
webReady = true;
}
This might help.
This maybe a good place to start. I know it's aimed at unit testing, but it automates control over IE and firefox and it's open source so you can download the code to see how they do it.
Hope it helps
Related
My program search for text inside files.
But what i want to do is to see the searching progress in real time.
I want to add the current file name search in to listView and also to display to a progressBar the percentages from 0 to 100%.
I added a backgroundworker but the way i'm using the ReportProgress is not working good. I need to wait for it to finish the foreach in the FindLines method and then only in the end i see the items in the listView and even then the items are a big mess.
This is the line that report:
backgroundWorker1.ReportProgress(0, fi.Name);
This is a screenshot of the items in the listView when the foreach is over:
What i want to do is to display the items adding to the listView in real time without waiting first to the operation over and also to add each item to a line and if a line is too long then later i will add a tip baloon or something. But now the listView look like a big mess.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Security.AccessControl;
using System.Security.Principal;
namespace Search_Text_In_Files
{
public partial class Form1 : Form
{
StreamWriter w = new StreamWriter(#"e:\textresults.txt");
public Form1()
{
InitializeComponent();
backgroundWorker1.RunWorkerAsync();
}
public List<string> FindLines(string DirName, string TextToSearch)
{
int counter = 0;
List<string> findLines = new List<string>();
DirectoryInfo di = new DirectoryInfo(DirName);
if (di != null && di.Exists)
{
if (CheckFileForAccess(DirName) == true)
{
foreach (FileInfo fi in di.EnumerateFiles("*", SearchOption.AllDirectories))
{
if (string.Compare(fi.Extension, ".cs", true) == 0)
{
backgroundWorker1.ReportProgress(0, fi.Name);
using (StreamReader sr = fi.OpenText())
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
if (s.Contains(TextToSearch))
{
counter++;
findLines.Add(s);
}
}
}
}
}
}
w.Close();
}
return findLines;
}
private bool CheckForAccess(string PathName)
{
// Determine if the path is a file or a directory
if (File.Exists(PathName) == true)
return CheckFileForAccess(PathName);
if (Directory.Exists(PathName) == true)
return CheckFolderForAccess(PathName);
return false;
}
private bool CheckFileForAccess(string FileName)
{
FileSecurity fs = new FileSecurity(FileName, AccessControlSections.Access);
if (fs == null)
return false;
AuthorizationRuleCollection TheseRules = fs.GetAccessRules(true, true, typeof(NTAccount));
if (TheseRules == null)
return false;
return CheckACL(TheseRules);
}
private bool CheckFolderForAccess(string FolderName)
{
DirectoryInfo di = new DirectoryInfo(FolderName);
if (di == null)
return false;
DirectorySecurity acl = di.GetAccessControl(AccessControlSections.Access);
if (acl == null)
return false;
AuthorizationRuleCollection TheseRules = acl.GetAccessRules(true, true, typeof(NTAccount));
if (TheseRules == null)
return false;
return CheckACL(TheseRules);
}
private bool CheckACL(AuthorizationRuleCollection TheseRules)
{
foreach (FileSystemAccessRule ThisRule in TheseRules)
{
if ((ThisRule.FileSystemRights & FileSystemRights.Read) == FileSystemRights.Read)
{
if (ThisRule.AccessControlType == AccessControlType.Deny)
return false;
}
// Run as many other checks as you like
}
return true;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
FindLines(#"d:\c-sharp", "string s1 = treeView1.SelectedNode.Tag as string;");
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
listView1.Items.Add(e.UserState.ToString());
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
}
}
}
This is a screenshot of the items in the listView when the foreach is
over: What i want to do is to display the items adding to the listView
in real time without waiting first to the operation over and also to
add each item to a line and if a line is too long then later i will
add a tip baloon or something. But now the listView look like a big
mess.
Did you try setting your Listview's view property to "List" ? That should display the file names in individual lines.
I think you should look into ObservableCollection(T). The collection fires events when items are added to it, and the UI element should automatically detect these changes and update the view.
At least that is how it works in WPF, but i think it should work as well in WinForms.
Read them back in app constructor and also maybe in other places in program.
I have a new form i created with some checkboxes:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace Options
{
public partial class OptionsMenuForm : Form
{
public OptionsMenuForm()
{
InitializeComponent();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
Settings.downloadonstart = true;
}
else
{
Settings.downloadonstart = false;
}
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
if (checkBox2.Checked)
{
Settings.loadonstart = true;
}
else
{
Settings.loadonstart = false;
}
}
private void checkBox3_CheckedChanged(object sender, EventArgs e)
{
if (checkBox3.Checked)
{
Settings.startminimized = true;
}
else
{
Settings.startminimized = false;
}
}
private void checkBox4_CheckedChanged(object sender, EventArgs e)
{
if (checkBox4.Checked)
{
Settings.displaynotifications = true;
}
else
{
Settings.displaynotifications = false;
}
}
}
}
Now i want to save each time the state of one/any of the checkboxes.
I also added a class i'm using th pass the variables between the new form and form1:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Options
{
class Settings
{
public static bool downloadonstart;
public static bool loadonstart;
public static bool startminimized;
public static bool displaynotifications;
}
}
Now how can i use this in form1 by saving the settings to a text file ?
For example in the text file the content will be something like:
CheckBox1 = true
CheckBox2 = false
CheckBox3 = false
CheckBox4 = true
And then if i change the state of one of them it will write it in the text file:
CheckBox1 = false
CheckBox2 = false
CheckBox3 = true
CheckBox4 = true
In form1 top i added
string settingsFile = "settings.txt";
string settingsFileDirectory = "\\settings";
StreamWriter writetosettingsfile;
Then in constructor
settingsFileDirectory = Path.GetDirectoryName(Application.LocalUserAppDataPath) +
settingsFileDirectory;
if (!Directory.Exists(settingsFileDirectory))
{
Directory.CreateDirectory(settingsFileDirectory);
}
I know the app it self have a settings in the properties but i wanted to use a text file this time since i have many settings and i might have more later.
Or using the settings in the app in properties i did:
But now how do i use with it in my program to save every checkbox state in the new form and then using it in form1 ?
You can use json.net
Something like this to save the data
private void Form1_Load(object sender, EventArgs e)
{
checkBox1.CheckedChanged += checkBox_CheckedChanged;
checkBox2.CheckedChanged += checkBox_CheckedChanged;
checkBox3.CheckedChanged += checkBox_CheckedChanged;
checkBox4.CheckedChanged += checkBox_CheckedChanged;
}
private void checkBox_CheckedChanged(object sender, EventArgs e)
{
var settings = new Settings();
settings.downloadonstart = checkBox1.Checked;
settings.loadonstart = checkBox2.Checked;
settings.startminimized = checkBox3.Checked;
settings.displaynotifications = checkBox4.Checked;
File.WriteAllText(#"c:\configfile.json", JsonConvert.SerializeObject(settings));
}
You can read the file like this
Settings settings = JsonConvert.DeserializeObject<Settings>(File.ReadAllText(#"c:\configfile.json"));
Documentation:
http://www.newtonsoft.com/json/help/html/Introduction.htm
public OptionsMenuForm()
{
InitializeComponent();
//Read the settings from a file with comma delimited 1's and 0's or whatever you like
string[] values = System.IO.File.ReadAllText("c:\temp\a.txt").Split(',');
checkBox1.Checked = Convert.ToBoolean(Convert.ToInt32(values[0]));
checkBox2.Checked = Convert.ToBoolean(Convert.ToInt32(values[1]));;
//On checkbox changes save the settings
checkBox1.CheckedChanged +=SaveSettings;
checkBox2.CheckedChanged +=SaveSettings;
}
public void SaveSettings(object sender,EventArgs e)
{
StringBuilder sbValues = new StringBuilder();
int i = 0;
i = checkBox1.Checked ? 1 : 0;
sbValues.Append(i.ToString() + ",");
i = checkBox2.Checked ? 1 : 0;
sbValues.Append(i.ToString() + ",");
System.IO.File.WriteAllText("c:\temp\a.txt",sbValues.ToString());
}
It is recommended that you use XML when using the .NET framework.
public static void ConvertStringToXmlList()
{
XElement xml = new XElement
(
"Items",
(
from x in [YourList] select new XElement("Item", x)
)
);
XDocument doc = new XDocument
(
xml
);
doc.Save(Environment.CurrentDirectory + "/settings.xml");
}
var xmlReader = new XmlTextReader("settings.xml");
while (xmlReader.Read())
{
switch (reader.NodeType)
{
case [nodetype]:
// Code here
break;
}
}
Also, instead of creating the same event for all four checkbox's, just use 1.
Inside of the single event put:
ckCheckBox1.Checked = !ckCheckBox1.Checked;
I'm trying to scrape a website to get data off of it. So far I got it to at least connect to the website, but now when I try to set the text of a textbox with the data, I just get a bunch of:
HtmlAgilityPack.HtmlNodeCollection
There are the same number of HtmlAgilityPack.HtmlNodeCollection as there is data. Here is my code ( it is a bit sloppy I know ):
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System;
using HtmlAgilityPack;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string choice;
public Form1()
{
InitializeComponent();
}
public void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
public void button1_Click(object sender, System.EventArgs e)
{
HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
htmlDoc.OptionFixNestedTags = true;
string urlToLoad = "http://www.nbcwashington.com/weather/school-closings/";
HttpWebRequest request = HttpWebRequest.Create(urlToLoad) as HttpWebRequest;
request.Method = "GET";
Console.WriteLine(request.RequestUri.AbsoluteUri);
WebResponse response = request.GetResponse();
htmlDoc.Load(response.GetResponseStream(), true);
if (htmlDoc.DocumentNode != null)
{
var articleNodes = htmlDoc.DocumentNode.SelectNodes("/html/body/div/div/div/div/div/div/p");
if (articleNodes != null && articleNodes.Any())
{
foreach (var articleNode in articleNodes)
{
textBox1.AppendText(htmlDoc.DocumentNode.SelectNodes("/html/body/div/div/div/div/div/div/p").ToString());
}
}
}
Console.ReadLine();
}
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
choice = listBox1.SelectedItem.ToString();
}
}
}
So what am I missing / doing wrong here? The data should return something like:
Warren County Public Schools Closed
Washington Adventist University Closing at Noon
Thanks for looking at this.
Nevermind, found the issue. I guess I was trying to grab the document node instead of the inner text... Here is code just in case anyone wants it.
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System;
using HtmlAgilityPack;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string choice;
public Form1()
{
InitializeComponent();
}
public void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
public void button1_Click(object sender, System.EventArgs e)
{
HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
htmlDoc.OptionFixNestedTags = true;
string urlToLoad = "http://www.nbcwashington.com/weather/school-closings/";
HttpWebRequest request = HttpWebRequest.Create(urlToLoad) as HttpWebRequest;
request.Method = "GET";
Console.WriteLine(request.RequestUri.AbsoluteUri);
WebResponse response = request.GetResponse();
htmlDoc.Load(response.GetResponseStream(), true);
if (htmlDoc.DocumentNode != null)
{
var articleNodes = htmlDoc.DocumentNode.SelectNodes("/html/body/div/div/div/div/div/div/p");
if (articleNodes != null && articleNodes.Any())
{
int k = 0;
foreach (var articleNode in articleNodes)
{
textBox1.AppendText(articleNode.InnerText + "\n");
}
}
}
Console.ReadLine();
}
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
choice = listBox1.SelectedItem.ToString();
}
}
}
Since articleNodes already contain the nodes you're interested in, there's no need to call SelectNodes() again inside a loop.
Also, you shouldn't need to check for null, since articleNodes is a collection. It might be empty, but shouldn't be null.
Try this, accessing the InnerHtml (or InnerText) property instead:
var articleNodes = htmlDoc.DocumentNode.SelectNodes("/html/body/div/div/div/div/div/div/p");
var result = articleNodes.Select(x => x.InnerHtml.Replace("<br><span>", " ")
.Replace(" </span>", "")).ToList();
I've been looking at similar posts to mine, but either my question is not answered, or I cannot understand the answer. I have used many code snippets off here to get started; so thanks for that ;-)
My requirement is to create an interactive cmd.exe window, and output results to text box ( to parse data ) eg, send command "cd /"; see the output then send command "dir" to show that I am in the new directory. Once I have this cracked, then I plan to parse the received text output and expand my application
I can currently do both things, but not at the same time.
I am new to c#, and have been stuck on this for a few days now. Code posted below.
proc1 manages to keep the session active, whereas proc2 outputs the text to a text box (I'll later on out it into a string to parse); but I can't manage to do both requirements at the same time.
I can explain more why I want to do this, but ultimately to create a concept application to expand once I have the basics cracked...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace ConsoleTest_07_07_14
{
public partial class Form1 : Form
{
Process proc1 = new Process();
Process proc2 = new Process();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
SetProc1();
proc1.Start();
SetProc2();
proc2.Start();
}
public void SetProc1()
{
proc1.StartInfo.FileName = #"C:\Windows\System32\cmd.exe";
proc1.StartInfo.WorkingDirectory = #"C:\Windows";
proc1.StartInfo.UseShellExecute = false;
proc1.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc2.StartInfo.CreateNoWindow = true;
proc1.StartInfo.RedirectStandardInput = true;
// proc2.StartInfo.RedirectStandardOutput = true;
}
public void SetProc2()
{
proc2.StartInfo.FileName = #"C:\Windows\System32\cmd.exe";
proc2.StartInfo.WorkingDirectory = #"C:\Windows";
proc2.StartInfo.UseShellExecute = false;
proc2.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc2.StartInfo.CreateNoWindow = true;
proc2.StartInfo.RedirectStandardInput = true;
proc2.StartInfo.RedirectStandardOutput = true;
}
private void button1_Click(object sender, EventArgs e)
{
// process1
StreamWriter SW1 = proc1.StandardInput;
SW1.WriteLine(textBox3.Text);
}
private void button2_Click(object sender, EventArgs e)
{
proc2.StartInfo.Arguments = "/c dir";
proc2.Start();
StreamReader SR2 = proc2.StandardOutput;
textBox2.Text = SR2.ReadToEnd();
}
}
}
If you're just looking to build your own cmd wrapper, basically input commands into a TextBox and output them to another TextBox, this will do:
public partial class Form1 : Form
{
string OutputData;
public Form1()
{
InitializeComponent();
}
public ProcessStartInfo SetProcStartInfo(string Command)
{
ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd.exe", "/c " + Command);
procStartInfo.WorkingDirectory = #"C:\Windows";
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
procStartInfo.RedirectStandardOutput = true;
return procStartInfo;
}
private void button1_Click(object sender, EventArgs e)
{
ProcessStartInfo procStartInfo = SetProcStartInfo(this.textBox1.Text);
using (Process proc1 = Process.Start(procStartInfo))
{
proc1.EnableRaisingEvents = true;
proc1.OutputDataReceived += OnOutputDataReceived;
proc1.BeginOutputReadLine();
}
}
void OnOutputDataReceived(object sender, DataReceivedEventArgs e)
{
if (e.Data != null)
{
this.OutputData += e.Data + Environment.NewLine;
SetText(this.OutputData);
}
}
delegate void SetTextCallback(string text);
private void SetText(string text)
{
if (this.textBox2.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object[] { text });
}
else
{
this.textBox2.Text = text;
}
}
}
I have managed to achieve what I wanted (Code below for reference) ( Thanks to a friend at work ;-) )
My aim was to keep a windows cmd session active, and capture any output text to a string to parse.
Eg, ssh to a linux box, run ifconfig, then parse out the interfaces available on the Linux box.
Ultimate aim is to give a software house an example of what I'd like them to expand on. I wanted Application to be written in c# as that is that foundation of the application I'd like to SW house to enhance.
Now I have the basics covered I'll look to do the ssh piece....
Thanks for all comments and replies
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace ConsoleTest_07_07_14
{
public partial class Form1 : Form
{
delegate void SetTextCallBack(string text);
Process proc1 = new Process();
string proc1_OutputText;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
SetProc1();
}
public void SetProc1()
{
proc1.StartInfo.FileName = #"C:\Windows\System32\cmd.exe";
proc1.StartInfo.WorkingDirectory = #"C:\Windows";
proc1.StartInfo.UseShellExecute = false;
proc1.StartInfo.CreateNoWindow = true;
proc1.StartInfo.RedirectStandardInput = true;
proc1.StartInfo.RedirectStandardError = true; //why was it false??
proc1.StartInfo.RedirectStandardOutput = true;
proc1.OutputDataReceived += new DataReceivedEventHandler(MyProc1OutputHandler);
proc1.ErrorDataReceived += new DataReceivedEventHandler(MyProc1OutputHandler);
proc1.Start();
proc1.BeginOutputReadLine();
}
private void button1_Click(object sender, EventArgs e)
{
// send command to process1
clearProc1_text();
SendProcessCommand(proc1, textBox2.Text);
}
private void SendProcessCommand (Process proc, string text)
{
StreamWriter SW = proc.StandardInput;
SW.WriteLine(text);
}
private void setProc1_OutputText(string text)
{
if (this.textBox1.InvokeRequired)
{
SetTextCallBack d = new SetTextCallBack(setProc1_OutputText);
this.Invoke(d, new object[] { text });
}
else
{
proc1_OutputText += text + Environment.NewLine;
this.textBox1.Text = proc1_OutputText;
}
}
private void clearProc1_text ()
{
clearText1();
clearProc1_OutputText();
}
private void clearText1() { textBox1.Text = ""; }
private void clearProc1_OutputText() { proc1_OutputText = ""; }
private static void MyProc1OutputHandler(object sendingProcess, DataReceivedEventArgs outline)
{
Debug.Print("Called");
if (!String.IsNullOrEmpty(outline.Data))
{ //Debug.Print(outline.Data)
Form1 f = (Form1)Form.ActiveForm;
if (f != null)
{
f.setProc1_OutputText(outline.Data);
}
}
}
}
}
All of a sudden my form window has begun to close as soon as the application is launched. There's nothing in the output window that gives a hint as to what could be causing it and there are no errors thrown at me either. Does anybody have any ideas?
I've provided to form's class.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ProjectBoardManagement {
public partial class CreateBoard : Form {
Functions funcs = new Functions();
public CreateBoard() {
InitializeComponent();
}
private void CreateBoardButton_Click(object sender, EventArgs e) {
String BoardName = BoardNameText.Text;
String Pages = "";
String Labels = "";
foreach (ListViewItem i in PageNameList.Items) {
Pages = (Pages + i.Name.ToString() + ",");
}
foreach (ListViewItem i in LabelNameList.Items) {
Labels = (Labels + i.Name.ToString() + ",");
}
String BoardFile = ("board_" + BoardName + ".txt");
funcs.SaveSetting(BoardFile, "name", BoardName);
funcs.SaveSetting(BoardFile, "pages", Pages);
funcs.SaveSetting(BoardFile, "labels", Labels);
FormManagement.CreateBoard.Hide();
FormManagement.BoardList.LoadBoardList();
}
private void PageNameButtonAdd_Click(object sender, EventArgs e) {
String pagename = PageNameText.Text;
if (pagename != "") {
PageNameList.Items.Add(pagename);
}
PageNameText.Text = "";
}
private void LabelNameButtonAdd_Click(object sender, EventArgs e) {
String labelname = LabelNameText.Text;
if (labelname != "") {
LabelNameList.Items.Add(labelname);
}
LabelNameText.Text = "";
}
}
}
Obvious first thing to do - run it in Debug mode and stop execution on all exceptions. This should give you enough information on how to go from there.
Otherwise Functions funcs = new Functions(); looks suspicious.