943,526 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 12833
  • C# RSS
May 20th, 2008
0

Browse Control in C#

Expand Post »
hi there,
is there a browse control in C# windows application form ,
if so , plz, how can I add it to my toolBox and how can I use it to allow the user to browse any file she wants,
if not how can I implement the idea og browsing ( that the user choose a file and then I do what ever I need with its path)

urgent help is neede pleease
Thanks in advance
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
knowledgelover is offline Offline
86 posts
since Nov 2007
May 20th, 2008
1

Re: Browse Control in C#

Reputation Points: 13
Solved Threads: 1
Newbie Poster
o.narasimharao is offline Offline
7 posts
since May 2008
May 20th, 2008
0

Re: Browse Control in C#

See attached from CodeProject
Attached Files
File Type: zip My_Explorer_src.zip (40.1 KB, 948 views)
Reputation Points: 69
Solved Threads: 75
Posting Pro in Training
JerryShaw is offline Offline
465 posts
since Nov 2006
May 20th, 2008
0

Re: Browse Control in C#

Ahhh Codeproject - love that site Jerry! I think (not tested it) this will work:

C# Syntax (Toggle Plain Text)
  1. OpenFileDialog op = new OpenFileDialog();
  2. op.ShowDialog();
Hope that helps! Just put that in the event handler of the button you wish to be the browse button!
Last edited by majestic0110; May 20th, 2008 at 3:46 pm. Reason: added code
Reputation Points: 256
Solved Threads: 72
Nearly a Posting Virtuoso
majestic0110 is offline Offline
1,306 posts
since Oct 2007
May 23rd, 2008
0

Re: Browse Control in C#

Did this solve your issue? If it did could you mark the thread as solved please so that others know it is solved!
Reputation Points: 256
Solved Threads: 72
Nearly a Posting Virtuoso
majestic0110 is offline Offline
1,306 posts
since Oct 2007
Sep 15th, 2008
0

Re: Browse Control in C#

C# Syntax (Toggle Plain Text)
  1. namespace GenerateHtmlNamespace
  2. {
  3. using System;
  4. using System.Drawing;
  5. using System.ComponentModel;
  6. using System.WinForms;
  7. using System.IO;
  8.  
  9. public class MakeHtml : Form
  10. {
  11. DialogResult s;
  12. private System.ComponentModel.Container components;
  13. private StatusBar statusBar1;
  14.  
  15. private Label label1;
  16. private Label label2;
  17.  
  18. private TextBox textBox1;
  19. private TextBox textBox2;
  20.  
  21. private Button button1;
  22. private Button button2;
  23. private Button button3;
  24. private Button button4;
  25. private Button button5;
  26. private GroupBox groupBox1;
  27. private GroupBox groupBox2;
  28.  
  29. private string nm = "";
  30. private string filename = "";
  31. private StreamWriter writer = null;
  32.  
  33. public MakeHtml()
  34. {
  35. InitializeComponent();
  36. }
  37.  
  38. public override void Dispose()
  39. {
  40. base.Dispose();
  41. components.Dispose();
  42. }
  43.  
  44. public static void Main(string[] args)
  45. {
  46. Application.Run(new MakeHtml());
  47. }
  48.  
  49. private void InitializeComponent()
  50. {
  51. this.components = new System.ComponentModel.Container();
  52.  
  53. this.label1 = new Label();
  54. this.label2 = new Label();
  55.  
  56. this.textBox1 = new TextBox();
  57. this.textBox2 = new TextBox();
  58.  
  59. this.groupBox1 = new GroupBox();
  60. this.groupBox2 = new GroupBox();
  61.  
  62. this.button1 = new Button();
  63. this.button2 = new Button();
  64. this.button3 = new Button();
  65. this.button4 = new Button();
  66. this.button5 = new Button();
  67.  
  68. this.statusBar1 = new StatusBar();
  69.  
  70. label1.Location = new System.Drawing.Point(88, 56);
  71. label1.Text = "Enter Your Name";
  72. label1.Size = new System.Drawing.Size(192, 32);
  73. label1.BorderStyle = System.WinForms.BorderStyle.FixedSingle;
  74. label1.ForeColor = System.Drawing.SystemColors.ActiveCaption;
  75. label1.Font = new System.Drawing.Font("Comic Sans MS", 12f);
  76. label1.BackColor = System.Drawing.Color.Bisque;
  77. label1.TextAlign = System.WinForms.HorizontalAlignment.Right;
  78.  
  79. label2.Location = new System.Drawing.Point(88, 104);
  80. label2.Text = "Enter HTML File Name ";
  81. label2.Size = new System.Drawing.Size(192, 32);
  82. label2.BorderStyle = System.WinForms.BorderStyle.FixedSingle;
  83. label2.ForeColor = System.Drawing.SystemColors.ActiveCaption;
  84. label2.Font = new System.Drawing.Font("Comic Sans MS", 12f);
  85. label2.BackColor = System.Drawing.Color.Bisque;
  86. label2.TextAlign = System.WinForms.HorizontalAlignment.Right;
  87.  
  88. textBox1.Location = new System.Drawing.Point(296, 56);
  89. textBox1.ForeColor = System.Drawing.SystemColors.ActiveCaption;
  90. textBox1.Font = new System.Drawing.Font("Lucida Sans Unicode", 12f);
  91. textBox1.Text = "Subhagata";
  92. textBox1.Size = new System.Drawing.Size(208, 32);
  93. textBox1.BackColor = System.Drawing.Color.NavajoWhite;
  94.  
  95. textBox2.Location = new System.Drawing.Point(296, 104);
  96. textBox2.ForeColor = System.Drawing.SystemColors.ActiveCaption;
  97. textBox2.Font = new System.Drawing.Font("Lucida Sans Unicode", 12f);
  98. textBox2.Text = "myFile.html";
  99. textBox2.Size = new System.Drawing.Size(208, 32);
  100. textBox2.BackColor = System.Drawing.Color.NavajoWhite;
  101.  
  102. button1.Location = new System.Drawing.Point(144, 280);
  103. button1.ForeColor = System.Drawing.SystemColors.ControlDarkDark;
  104. button1.BackColor = System.Drawing.SystemColors.ControlLight;
  105. button1.Size = new System.Drawing.Size(112, 40);
  106. button1.Font = new System.Drawing.Font("Times New Roman", 12f);
  107. button1.Text = "Make HTML";
  108. button1.Click += new System.EventHandler(button1_Click);
  109.  
  110. button2.Location = new System.Drawing.Point(256, 280);
  111. button2.ForeColor = System.Drawing.SystemColors.ControlDarkDark;
  112. button2.BackColor = System.Drawing.SystemColors.ControlLight;
  113. button2.Size = new System.Drawing.Size(112, 40);
  114. button2.Font = new System.Drawing.Font("Times New Roman", 12f);
  115. button2.Text = "Clear";
  116. button2.Click += new System.EventHandler(button2_Click);
  117.  
  118. button3.Location = new System.Drawing.Point(368, 280);
  119. button3.ForeColor = System.Drawing.SystemColors.ControlDarkDark;
  120. button3.BackColor = System.Drawing.SystemColors.ControlLight;
  121. button3.Size = new System.Drawing.Size(104, 40);
  122. button3.Font = new System.Drawing.Font("Times New Roman", 12f);
  123. button3.Text = "Exit";
  124. button3.Click += new System.EventHandler(button3_Click);
  125.  
  126. button4.Location = new System.Drawing.Point(184, 184);
  127. button4.ForeColor = System.Drawing.Color.DarkSlateGray;
  128. button4.BackColor = System.Drawing.SystemColors.ControlLight;
  129. button4.Size = new System.Drawing.Size(120, 32);
  130. button4.Font = new System.Drawing.Font("Times New Roman", 8f);
  131. button4.Text = "Change Window Color";
  132. button4.Click += new System.EventHandler(button4_Click);
  133.  
  134. button5.Location = new System.Drawing.Point(304, 184);
  135. button5.ForeColor = System.Drawing.Color.DarkSlateGray;
  136. button5.BackColor = System.Drawing.SystemColors.ControlLight;
  137. button5.Size = new System.Drawing.Size(120, 32);
  138. button5.Font = new System.Drawing.Font("Times New Roman", 8f);
  139. button5.Text = "Change Label Color";
  140. button5.Click += new System.EventHandler(button5_Click);
  141.  
  142. groupBox1.Location = new Point(96, 256);
  143. groupBox1.Text = "Action";
  144. groupBox1.Size = new Size(416, 88);
  145.  
  146. groupBox2.Location = new Point(85, 168);
  147. groupBox2.Text = "Customize Window Settings";
  148. groupBox2.Size = new Size(432, 64);
  149.  
  150. statusBar1.Location = new Point(0, 200);
  151. statusBar1.Size = new Size(200, 16);
  152. statusBar1.Text = "Enter Details";
  153.  
  154. this.Text = "MakeHtml";
  155. this.Cursor = Cursors.PanNW;
  156. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  157. this.BackColor = System.Drawing.SystemColors.GrayText;
  158. this.ClientSize = new System.Drawing.Size(592, 485);
  159. this.StartPosition = FormStartPosition.CenterScreen;
  160.  
  161. this.Controls.Add(label1);
  162. this.Controls.Add(label2);
  163.  
  164. this.Controls.Add(textBox1);
  165. this.Controls.Add(textBox2);
  166.  
  167. this.Controls.Add(button1);
  168. this.Controls.Add(button2);
  169. this.Controls.Add(button3);
  170. this.Controls.Add(button4);
  171. this.Controls.Add(button5);
  172.  
  173. this.Controls.Add(groupBox1);
  174. this.Controls.Add(groupBox2);
  175.  
  176. this.Controls.Add(statusBar1);
  177. }
  178.  
  179. protected void button1_Click(object sender, System.EventArgs e)
  180. {
  181. nm = textBox1.Text.Trim();
  182. filename = textBox2.Text.Trim();
  183.  
  184. if((textBox1.Text == "") || (textBox2.Text == ""))
  185. {
  186. statusBar1.Text = "Please enter the required details.";
  187. textBox1.Focus();
  188. }
  189.  
  190. else
  191. {
  192. if(GenerateCode())
  193. {
  194. statusBar1.Text = "Html code generated to file "+filename;
  195. }
  196. else
  197. {
  198. statusBar1.Text = "Error";
  199. }
  200. }
  201. }
  202.  
  203. protected void button2_Click(object sender, System.EventArgs e)
  204. {
  205. textBox1.Text = "";
  206. textBox2.Text = "";
  207. statusBar1.Text = "Cleared All";
  208. }
  209.  
  210. protected void button3_Click(object sender, System.EventArgs e)
  211. {
  212. this.Close();
  213. }
  214.  
  215. protected void button4_Click(object sender, System.EventArgs e)
  216. {
  217. ColorDialog colorDialog1 = new ColorDialog();
  218. colorDialog1.AllowFullOpen=false;
  219.  
  220. colorDialog1.ShowDialog();
  221. Color objColor = colorDialog1.Color;
  222. this.BackColor=objColor;
  223. }
  224.  
  225. protected void button5_Click(object sender, System.EventArgs e)
  226. {
  227. ColorDialog colorDialog1 = new ColorDialog();
  228. colorDialog1.AllowFullOpen=false;
  229.  
  230. colorDialog1.ShowDialog();
  231. Color objColor = colorDialog1.Color;
  232. label1.ForeColor=objColor;
  233. label2.ForeColor=objColor;
  234. }
  235.  
  236. private bool GenerateCode()
  237. {
  238. File f = new File(filename);
  239. if(f.Exists)
  240. {
  241. s=MessageBox.Show("This fils already exists. Do you want to delete it ???" , "Worning" , MessageBox.YesNo | MessageBox.IconExclamation);
  242. if(String.Format("{0}" , s) == "Yes")
  243. {
  244. f.Delete();
  245. }
  246. else
  247. {
  248. s=MessageBox.Show("Enter a different file name." , "Worning");
  249. textBox2.Focus();
  250. }
  251.  
  252. }
  253.  
  254. FileStream outputfile = null;
  255. try
  256. {
  257. outputfile = new FileStream(filename,FileMode.OpenOrCreate, FileAccess.Write);
  258.  
  259. writer = new StreamWriter(outputfile);
  260.  
  261. writer.BaseStream.Seek(0, SeekOrigin.End);
  262.  
  263. DoWrite ("<HTML>");
  264. DoWrite ("<HEAD>");
  265. DoWrite ("<TITLE>");
  266. DoWrite ("This HTML file is create in C#");
  267. DoWrite ("</TITLE>");
  268. DoWrite ("</HEAD>");
  269. DoWrite ("<BODY BGCOLOR='Tan'>");
  270. DoWrite ("<CENTER>");
  271. DoWrite ("<BR><BR><H2>Hello " + nm + "</H2>");
  272. DoWrite ("<BR><H4><A HREF='http://www.csharphelp.com'>www.csharphelp.com</A></H4>");
  273. DoWrite ("</CENTER>");
  274. DoWrite ("</BODY>");
  275. DoWrite ("</HTML>");
  276. writer.Close();
  277. }
  278. catch(Exception ex)
  279. {
  280. Console.WriteLine("Exception GenerateCode = "+ex);
  281. statusBar1.Text = "Error";
  282. outputfile = null;
  283. writer = null;
  284. return false;
  285. }
  286. return true;
  287. }
  288.  
  289. private void DoWrite (String line)
  290. {
  291. writer.WriteLine(line);
  292. writer.Flush();
  293. }
  294. }
  295. }
Last edited by cscgal; Sep 15th, 2008 at 11:18 am. Reason: Added code tags
Reputation Points: 10
Solved Threads: 1
Newbie Poster
johnblesswin is offline Offline
1 posts
since Sep 2008
Jan 15th, 2009
0

Re: Browse Control in C#

FileView Control from Shell MegaPack http://www.ssware.com/megapack.htm is worth a look - it can be put in your windows forms and allows users to browse for files/folders
Reputation Points: 10
Solved Threads: 1
Newbie Poster
mmaster is offline Offline
3 posts
since Jan 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Object reference not set to an instance of an object.
Next Thread in C# Forum Timeline: file browser





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC