Foro de Visual C# GeneralGeneral discussion and questions regarding Visual C# -- including best practices on developing with C# in VS, documentation, setup, and samples.© 2009 Microsoft Corporation. Todos los derechos reservados.Sun, 29 Nov 2009 18:39:23 Z24becc9b-b984-47b2-a748-a62e38c0066fhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/d4de8c07-f24a-48cd-ad5f-aba3e5c60f1dhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/d4de8c07-f24a-48cd-ad5f-aba3e5c60f1dMDMourahttp://social.msdn.microsoft.com/Profile/es-ES/?user=MDMouraStatic, Constructor and Parameter.Hello,<br/> <br/> I have the following code:<br/> <pre lang="x-c#"> public class ValidatorFactory : IValidatorFactory {<br/> <br/> private static IMembershipService _service;<br/> private static Dictionary&lt;Type, IValidator&gt; _validators = new Dictionary&lt;Type, IValidator&gt;();<br/> <br/> static ValidatorFactory() {<br/> _validators.Add(typeof(ProductEdit), new ProductEditValidator());<br/> _validators.Add(typeof(UserSignIn), new UserSignInValidator(_service)); <br/> } // ValidatorFactory<br/> <br/> public IValidator&lt;T&gt; GetValidator&lt;T&gt;() {<br/> return (IValidator&lt;T&gt;)GetValidator(typeof(T));<br/> } // GetValidator<br/> <br/> public IValidator&lt;T&gt; GetValidator&lt;T&gt;(IMembershipService service) {<br/> _service = service;<br/> return (IValidator&lt;T&gt;)GetValidator(typeof(T));<br/> } // GetValidator<br/> <br/> public IValidator GetValidator(Type type) {<br/> IValidator validator;<br/> if (_validators.TryGetValue(type, out validator))<br/> return validator;<br/> return null;<br/> } // GetValidator<br/> <br/> } // ValidatorFactory<br/> <br/> </pre> To use it as follows:<br/> <br/> <pre lang="x-c#">_validatorFactory.GetValidator&lt;UserSignIn&gt;(_membershipService).Validate(model).AddToModelState(ModelState, String.Empty);</pre> The problem is that inside UserSignIn validator the membershipService is always null.<br/> <br/> I think I should define the MembershipService in ValidationFactory constructor and not in GetValidator.<br/> <br/> But then I get problems with static.<br/> <br/> Is there a way to solve this?<br/> <br/> Thanks,<br/> MiguelSun, 29 Nov 2009 18:39:22 Z2009-11-29T18:39:22Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/2926dbc4-a96a-490b-8418-6f674b9bf1e4http://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/2926dbc4-a96a-490b-8418-6f674b9bf1e4Tatworthhttp://social.msdn.microsoft.com/Profile/es-ES/?user=TatworthIs it better to var than an explicit type?In a function like:<br/> string test = &quot;Hello World&quot;<br/> <br/> string can be replaced by var. This has been advocated as a useful refactor in some quarters --- why?Sat, 28 Nov 2009 21:23:58 Z2009-11-29T18:18:46Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/b89c5002-e14d-439d-a8e8-1d106970f339http://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/b89c5002-e14d-439d-a8e8-1d106970f339Ravish_86http://social.msdn.microsoft.com/Profile/es-ES/?user=Ravish_86How to print each node of xml fileHi,<br/> <br/> I have xml file in which each node has many child nodes and again each child node has many childs and so on. I need to print each node name and value of xml document.  I want to do in c# language. Can any one tell me how to traverse xml file.<br/> <br/> Here is example of xml file<br/> <br/> <br/> &lt;data&gt;<br/>   &lt;file&gt;<br/>      &lt;name&gt;gunjan.txt&lt;/name&gt;<br/>      &lt;path&gt;c://temp&lt;/path&gt;<br/>   &lt;/file&gt;<br/> &lt;file&gt;<br/>      &lt;name&gt;kajal.txt&lt;/name&gt;<br/>      &lt;path&gt;c://temp&lt;/path&gt;<br/>   &lt;/file&gt;<br/> &lt;/data&gt;<br/> <br/>Sun, 29 Nov 2009 15:07:51 Z2009-11-29T18:13:37Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/c93e8e3d-f877-49f0-b552-64137c980abchttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/c93e8e3d-f877-49f0-b552-64137c980abcRyan McBeehttp://social.msdn.microsoft.com/Profile/es-ES/?user=Ryan%20McBeeMethod Name Expected Compile Error - Windows Service Timer ProjectI have a Window Service project that has a timer.  I have a line of code in the Timer Event that kicks off a method.  However, I am having trouble passing through my parameters in this line.  I am getting a compile error that reads &quot;Method Name Expected&quot;.  Any thoughts?<br/><br/><span style="font-size:x-small"><font size=2> <p>_timer.Elapsed +=</p> </font></span> <p><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">new</span></span><span style="font-size:x-small"> System.Timers.</span><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">ElapsedEventHandler</span></span><span style="font-size:x-small">(MoveFiles(</span><span style="color:#a31515;font-size:x-small"><span style="color:#a31515;font-size:x-small">@&quot;C:\temp&quot;</span></span><span style="font-size:x-small">,</span><span style="color:#a31515;font-size:x-small"><span style="color:#a31515;font-size:x-small">@&quot;C:\temp&quot;</span></span><span style="font-size:x-small">,</span><span style="color:#a31515;font-size:x-small"><span style="color:#a31515;font-size:x-small">&quot;*.txt&quot;</span></span><span style="font-size:x-small">));<br/><br/>My method called MoveFiles is defined as follows;<br/><br/><span style="font-size:x-small"><font size=2> <p> </p> </font></span> <p><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">public</span></span><span style="font-size:x-small"> </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">static</span></span><span style="font-size:x-small"> </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">void</span></span><span style="font-size:x-small"> MoveFiles(</span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">string</span></span><span style="font-size:x-small"> sourceDir, </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">string</span></span><span style="font-size:x-small"> destinationDir, </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">string</span></span><span style="font-size:x-small"> pattern) <p>{</p> <font size=2> <p> </p> </font></span></p> <p><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">var</span></span><span style="font-size:x-small"> fileQuery = </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">from</span></span><span style="font-size:x-small"> f </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">in</span></span><span style="font-size:x-small"> </span><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">Directory</span></span><span style="font-size:x-small">.GetFiles(sourceDir, pattern)<font size=2> <p> </p> </font></span></p> <p><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">select</span></span><span style="font-size:x-small"> </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">new</span></span><span style="font-size:x-small"> {Source = f,Destination = </span><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">Path</span></span><span style="font-size:x-small">.Combine(destinationDir, </span><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">Path</span></span><span style="font-size:x-small">.GetFileName(f))}; <p> </p> <font size=2> <p>fileQuery.ToList().ForEach(f =&gt;</p> </font></span></p> <p><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">File</span></span><span style="font-size:x-small">.Move(f.Source, f.Destination)); <p>}<br/><br/>Any help is appreciated!<br/><br/>Thanks,<br/>Ryan</p> </span></p> </span></p>Sun, 29 Nov 2009 17:29:00 Z2009-11-29T17:43:44Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/8a5ff52e-cbfa-4546-b14f-7ca24755bfadhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/8a5ff52e-cbfa-4546-b14f-7ca24755bfadnemesiscsharphttp://social.msdn.microsoft.com/Profile/es-ES/?user=nemesiscsharpHow to pass data from form1 to form2?Got a problem in passing a value from form1's textbox to form2's textbox.<br/> By the way i am using mysql connection.<br/> <br/> Can someone help me? :) thanksSat, 28 Nov 2009 02:16:41 Z2009-11-29T17:20:13Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/5c73b074-a7db-4a43-b656-50bee32734b5http://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/5c73b074-a7db-4a43-b656-50bee32734b5AlexBB - Vista Ult64 SqlSer64 WinSer64http://social.msdn.microsoft.com/Profile/es-ES/?user=AlexBB%20-%20Vista%20Ult64%20SqlSer64%20WinSer64ZedGraphI just spent a couple of hours trying to implement ZedGraph. I downloaded the dlls from SourceForge website:<br/><br/><a href="http://sourceforge.net/projects/zedgraph/files/">http://sourceforge.net/projects/zedgraph/files/</a><br/><br/>and dropped them into VS2008 ToolBox. I followed all instructions, opened up a new project and dropped the control on one of my Tabpages. The look is very good. What I don't understand is this. I am trying to use the tutorial, A Flexible Charting Library in .NET:<br/><br/><a href="http://www.codeproject.com/KB/graphics/zedgraph.aspx">http://www.codeproject.com/KB/graphics/zedgraph.aspx</a><br/><br/>and follow code samples which are also all over the web. it seems to me this latest version of the dlls is different from the one code samples relate to. I cannot invoke some classes and some methods are absent in the classes that are available. It also appears that come NameSpaces are rearranged. Before I spent another two hours I want to ask the public if anyone has had recent experience with the control. Am I doing something wrong?<br/><br/>For instance this code sample:<br/><br/>private void CreateGraph( ZedGraphControl zgc )<br/>{<br/>   // get a reference to the GraphPane<br/>   GraphPane myPane = zgc.GraphPane;<br/><br/>gives me compilation errors. ZedGraphControl  is not available as an object. I can get the Panel differently but I don't know how to connect it to the page or the graph.<br/><br/>This is how it works for me:<br/><br/>        private void CreateGraph ( ZedGraph zgc )<br/>        {<br/>            // get a reference to the GraphPane<br/>            ZedGraph.GraphPane myPane = new ZedGraph.GraphPane ( );            <br/>            // Set the Titles<br/>            myPane.Title.Text = &quot;My Test Graph\n(For CodeProject Sample)&quot;;<br/>            myPane.XAxis.Title.Text = &quot;My X Axis&quot;;<br/>            myPane.YAxis.Title.Text = &quot;My Y Axis&quot;;<br/><br/>Thanks.<br/><br/><br/><br/> <hr class=sig> AlexBSat, 28 Nov 2009 22:18:19 Z2009-11-29T17:10:07Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/17b153a9-f271-4861-bc31-055e89bc5719http://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/17b153a9-f271-4861-bc31-055e89bc5719DavidThi808http://social.msdn.microsoft.com/Profile/es-ES/?user=DavidThi808Free book: No Bugs!<img src="http://blogs.windwardreports.com/.a/6a0115711bf0ae970b012875e00c90970c-pi" alt="" align=left> <p>I wrote this book in what now looks like the dawn of antiquity. I was on the Windows 95 development team at the time – C++ was still new, we still wrote the time critical parts in assembler, and Java was a word for coffee. It was a challenging world back then. Not better than today, not worse – but different challenges.</p> <p>I went back and looked at what I wrote. A lot of it is specific to C, C++, and assembler. Some of it is specific to the state of the industry at that time. And those parts will only be of interest to a few with a large degree of curiosity about that time. A bit more will be of interest to people still writing C++ in an unmanaged environment.</p> <p>But the first two chapters, those are still every bit as relevant today as they were when the book was written. I think most developers can be well served by reading this as it takes a philosophical look at how to write code with fewer bugs.</p> <p>You can download the entire book <strong>for free</strong> at <a href="http://www.windwardreports.com/free.htm">No Bugs!</a> You may forward the free copy to friends, post it on your own website, etc. Below is a short excerpt from chapters 1 &amp; 2 if you want a peek before downloading.</p> <p style="margin-left:36pt">One interesting note, in chapter 2 it declares bugs should be called <strong>Massive F*** Ups</strong>. The use of the F word had to be approved by a Vice President at the publisher and I think to this day No Bugs! Remains the one programming book from a major publisher where the word appears.</p> download <a href="http://www.windwardreports.com/free.htm">No Bugs!</a> <hr class=sig> Windward Reports - <a href="http://www.windwardreports.com">World's Greatest SharePoint Reporting &amp; DocGen</a>Sun, 29 Nov 2009 02:49:00 Z2009-11-29T16:54:21Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/15a7bb3e-34c0-41a0-b7f7-48c851f87696http://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/15a7bb3e-34c0-41a0-b7f7-48c851f87696raptor6http://social.msdn.microsoft.com/Profile/es-ES/?user=raptor6Parsing Date to String in queryHi!<br/>Im trying to select from table Date.<br/>I have method DoScalarString.<br/><br/>But if I write: <br/>string CourseStartDate = DBOperations.DoScalarString(&quot;<span style="font-size:x-small"><span style="color:#800000">SELECT StartDate FROM Courses WHERE Title = '&quot;</span>+txt_course_client.Text+<span style="color:#800000"><span style="color:#800000">&quot;'&quot;</span></span>);</span> <br/><br/><br/>I get can't cast DateTime to String<br/><br/><br/>If I try (&quot;Select VALUE CAST (StartDate AS string) FROM.....&quot;),<br/><br/>I get &quot;IErrorInfo.GetDescription failed with E_Fail(0X.....)&quot;<br/><br/>If I do this:<br/><br/><span style="color:#008080;font-size:x-small"><span style="color:#008080;font-size:x-small"><font size=2 color="#008080"><font size=2 color="#008080"> <p>DateTime</p> </font></font></span><font size=2 color="#008080"> <p> </p> </font></span> <p><span style="font-size:x-small"> CourseStartDate = </span><span style="color:#008080;font-size:x-small"><span style="color:#008080;font-size:x-small">DBOperations</span></span><span style="font-size:x-small">.DoScalarDateTime(</span><span style="color:#800000;font-size:x-small"><span style="color:#800000;font-size:x-small">&quot;SELECT StartDate FROM Courses WHERE Title = '&quot;</span></span><span style="font-size:x-small">+txt_course_client.Text+</span><span style="color:#800000;font-size:x-small"><span style="color:#800000;font-size:x-small">&quot;'&quot;</span></span><span style="font-size:x-small">);<font size=2> <p>Folowinf works, but I it needs a whole method additionally. Is there a way to make it like I tried with CAST? Where is there bug?<br/><br/>Thanks!</p> </font></span></p> <p><span style="color:#008080;font-size:x-small"></span></p>Fri, 27 Nov 2009 20:09:32 Z2009-11-29T16:02:58Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/28d7c9c9-03ff-4d32-9502-5c1dee9e49fdhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/28d7c9c9-03ff-4d32-9502-5c1dee9e49fdSuperMathhttp://social.msdn.microsoft.com/Profile/es-ES/?user=SuperMathquestion about sending form via postI'm using &quot;HttpWebRequest&quot; in order to send a web form via &quot;post&quot;.<br/> but I have a problem, the site get a component like this one: &lt;input <strong>type=&quot;file&quot;</strong> name=&quot;the_file&quot;....&gt;<br/> how can I add a file to the post data? I mean adding it to the post string: &quot;domain_lang=en&amp;action=upload&amp;the_file=........&quot;<br/> <br/> thanks.Thu, 26 Nov 2009 11:29:25 Z2009-11-29T15:04:24Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/ead69a43-464a-48b8-88cb-686cd3714423http://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/ead69a43-464a-48b8-88cb-686cd3714423tosa.yasunarihttp://social.msdn.microsoft.com/Profile/es-ES/?user=tosa.yasunariBitmap handling of 16bit gray tiff imageI'm quite annoyed by Bitmap reading a 16 bit gray tiff image.    When I do new Bitmap(filename), I get PixelFormat being Format32bppArgb and I get a black image.<br/> <br/> Is there any way to get Bitmap translated exactly what the original one is, i.e. getting Format16bppGrayScale?<br/> <br/> Thank you.Sun, 29 Nov 2009 05:27:01 Z2009-11-29T14:50:34Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/e3e9a0c6-3f3f-40f1-aec0-4d2cdb50ea2chttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/e3e9a0c6-3f3f-40f1-aec0-4d2cdb50ea2cRavish_86http://social.msdn.microsoft.com/Profile/es-ES/?user=Ravish_86How to load schema into xmldocument and how to validate xml file with schema file<br/> Hi,<br/> <br/> I have schema file but this file is not .xsd file. Can anyone please tell me how to load this file into xmldocument to create xml file and how to validate any xml file with this schema.<br/> <br/> <br/> &lt;Schema name=&quot;DTMDeviceStatusSchema&quot; xmlns=&quot;urn:schemas-microsoft-com:xml-data&quot; xmlns:dt=&quot;urn:schemas-microsoft-com:datatypes&quot; xmlns:fdt=&quot;x-schema:FDTDataTypesSchema.xml&quot;&gt;<br/>     &lt;!--Definition of Attributes--&gt;<br/>     &lt;AttributeType name=&quot;deviceInitiatedCommunication&quot; dt:type=&quot;boolean&quot;/&gt;                           <br/>     &lt;ElementType name=&quot;DtmDeviceStatus&quot; content=&quot;mixed&quot; model=&quot;closed&quot;&gt;<br/>         &lt;attribute type=&quot;fdt:nodeId&quot; required=&quot;no&quot;/&gt;<br/>         &lt;attribute type=&quot;fdt:statusFlag&quot; required=&quot;yes&quot;/&gt;<br/>         &lt;attribute type=&quot;deviceInitiatedCommunication&quot; required=&quot;no&quot;/&gt;                                           <br/>         &lt;element type=&quot;fdt:StatusInformation&quot; minOccurs=&quot;0&quot; maxOccurs=&quot;1&quot;/&gt;<br/>     &lt;/ElementType&gt;<br/>     &lt;ElementType name=&quot;FDT&quot; content=&quot;eltOnly&quot; model=&quot;closed&quot;&gt;<br/>         &lt;attribute type=&quot;fdt:nodeId&quot; required=&quot;no&quot;/&gt;<br/>         &lt;element type=&quot;DtmDeviceStatus&quot; minOccurs=&quot;1&quot; maxOccurs=&quot;1&quot;/&gt;<br/>     &lt;/ElementType&gt;<br/> &lt;/Schema&gt;<br/>Sun, 29 Nov 2009 14:41:50 Z2009-11-29T14:41:50Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/47d40914-fb51-4c38-a5cd-5e3a5dfd9a3chttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/47d40914-fb51-4c38-a5cd-5e3a5dfd9a3cRicky Joelhttp://social.msdn.microsoft.com/Profile/es-ES/?user=Ricky%20JoelPhone Call Logging in C# & WinformsHi, I am trying to develop a C# application to record phone calls, store and play back them. I am using splitter to split the phone line to the receiver and the computer's sound input. When there is incoming phone and if the receiver is picked up i have to start recording the call and once the call is ended recording should be stopped and the file should be saved to the hard drive. I have done the scenario by clicking button controls in the form. But i need to do it automatically. Please anyone give ideas. <br/><br/>Thanks in Advance <br/><br/>Ricky JoelSun, 29 Nov 2009 14:34:10 Z2009-11-29T14:34:11Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/cb234a84-3449-494d-bcd9-7827c3f13371http://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/cb234a84-3449-494d-bcd9-7827c3f13371alainkkkhttp://social.msdn.microsoft.com/Profile/es-ES/?user=alainkkkfilter hi how do i act the rowfilter to have the autocomplete textbox feature? <div><br/></div> <div> <pre><pre> private void txtCodeSearch_TextChanged(object sender, EventArgs e) { dv.RowFilter =&quot; Operations like '&quot;+ txtCodeSearch.Text+&quot;%'&quot;;</pre> <br/></pre> i tried this above, but it canot fulfill the needs of my requirement.<br/><br/></div> <div>given the sample, </div> <div>111</div> <div>1122</div> <div>44</div> <div>55</div> <div>abc</div> <div>matthew</div> <div><br/></div> <div>when i type in 1 in the textbox, it should filter those data without the 1 infront. left with just 111, 1122</div> <hr class=sig> alainSun, 29 Nov 2009 12:43:16 Z2009-11-29T13:12:53Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/41716995-9320-4925-a66b-80f9c313a283http://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/41716995-9320-4925-a66b-80f9c313a283alainkkkhttp://social.msdn.microsoft.com/Profile/es-ES/?user=alainkkkshorten my codehi how do i shorten this junk of code <div> <pre lang="x-c#"><pre> private void toolStrip_Operation_Click(object sender, EventArgs e) { OperationForm limo = new OperationForm(); toolStripContainer1.ContentPanel.Controls.Clear(); toolStripContainer1.ContentPanel.Controls.Add(limo); limo.Dock = DockStyle.Fill; }</pre> <br/></pre> into seomthing like this below?</div> <div> <pre lang="x-c#"> private void toolStrip_Operation_Click(object sender, EventArgs e) { OperationForm limo = new OperationForm(); OpenForm(limo); } private void OpenForm(object sender) { toolStripContainer1.ContentPanel.Controls.Clear(); toolStripContainer1.ContentPanel.Controls.Add(sender); sender = DockStyle.Fill; }</pre> this is because i need to reuse this code for my others toolstrip</div><hr class="sig">alainSat, 28 Nov 2009 13:16:41 Z2009-11-29T11:57:13Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/63a2fac2-25d4-4c77-b529-d1bbe20aa6f9http://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/63a2fac2-25d4-4c77-b529-d1bbe20aa6f9alexis4http://social.msdn.microsoft.com/Profile/es-ES/?user=alexis4Disable windows hotkeys, C#Hello!<br/> <br/> I am developing a full screen mode application, where all windows hotkeys that exit application from full screen, need to be disabled. I could disable ALT+TAB, ALT+F4 and ALT+ESC using the following code I found in the internet:<br/> <br/> <div style="color:Black;background-color:White"> <pre><span style="color:Blue">namespace</span> MyNamespace { <span style="color:Blue">public</span> <span style="color:Blue">partial</span> <span style="color:Blue">class</span> MainForm : Form { <span style="color:Blue">#region</span> Dynamic Link Library Imports [DllImport(<span style="color:#a31515">&quot;user32.dll&quot;</span> )] <span style="color:Blue">private</span> <span style="color:Blue">static</span> <span style="color:Blue">extern</span> <span style="color:Blue">int</span> RegisterHotKey<br/> (IntPtr hwnd, <span style="color:Blue">int</span> id, <span style="color:Blue">int</span> fsModifiers, <span style="color:Blue">int</span> vk); [DllImport(<span style="color:#a31515">&quot;user32.dll&quot;</span> )] <span style="color:Blue">private</span> <span style="color:Blue">static</span> <span style="color:Blue">extern</span> <span style="color:Blue">int</span> UnregisterHotKey<br/> (IntPtr hwnd, <span style="color:Blue">int</span> id); <span style="color:Blue">#endregion</span> <span style="color:Blue">#region</span> Modifier Constants and Variables <span style="color:Green">// Constants for modifier keys</span> <span style="color:Blue">private</span> <span style="color:Blue">const</span> <span style="color:Blue">int</span> USE_ALT = 1; <span style="color:Blue">private</span> <span style="color:Blue">const</span> <span style="color:Blue">int</span> USE_CTRL = 2; <span style="color:Blue">private</span> <span style="color:Blue">const</span> <span style="color:Blue">int</span> USE_SHIFT = 4; <span style="color:Blue">private</span> <span style="color:Blue">const</span> <span style="color:Blue">int</span> USE_WIN = 8; <br/> <span style="color:Green">// Hot key ID tracker</span> <span style="color:Blue"> short</span> mHotKeyId = 0; <span style="color:Blue">#endregion</span> <span style="color:Blue">public</span> MainForm() { InitializeComponent(); RegisterGlobalHotKey(Keys.Tab, USE_ALT); <span style="color:Green">//Block Alt+TAB</span> RegisterGlobalHotKey(Keys.F4, USE_ALT); <span style="color:Green">//Block Alt+F4</span> RegisterGlobalHotKey(Keys.Escape, USE_ALT);<span style="color:Green">//Block Alt+ESC&lt;br/&gt;</span> } <span style="color:Blue">private</span> <span style="color:Blue">void</span> RegisterGlobalHotKey<br/> (Keys hotkey, <span style="color:Blue">int</span> modifiers) { <span style="color:Blue">try</span> { <span style="color:Green">// increment the hot key value - we are just identifying</span> <span style="color:Green">// them with a sequential number since we have multiples</span> mHotKeyId++; <span style="color:Blue">if</span> (mHotKeyId &gt; 0) { <span style="color:Green">// register the hot key combination</span> <span style="color:Blue">if</span> (RegisterHotKey(<span style="color:Blue">this</span> .Handle, mHotKeyId, modifiers, Convert.ToInt16(hotkey)) == 0) { <span style="color:Green">// tell the user which combination failed to register </span> <span style="color:Green">// this is useful to you, not an end user; the user</span> <span style="color:Green">// should never see this application run</span> MessageBox.Show(<span style="color:#a31515">&quot;Error: &quot;</span> + mHotKeyId.ToString() + <span style="color:#a31515">&quot; - &quot;</span> + Marshal.GetLastWin32Error().ToString(), <span style="color:#a31515">&quot;Hot Key Registration&quot;</span> ); } } } <span style="color:Blue">catch</span> { <span style="color:Green">// clean up if hotkey registration failed -</span> <span style="color:Green">// nothing works if it fails</span> UnregisterGlobalHotKey(); } } <span style="color:Blue">private</span> <span style="color:Blue">void</span> UnregisterGlobalHotKey() { <span style="color:Green">// loop through each hotkey id and</span> <span style="color:Green">// disable it</span> <span style="color:Blue">for</span> (<span style="color:Blue">int</span> i = 0; i &lt; mHotKeyId; i++) { UnregisterHotKey(<span style="color:Blue">this</span> .Handle, i); } } <span style="color:Green">//rest of user code</span> } } </pre> </div> <br/> I need to disable CTR+ESC and the Windows key (right and left). I called the RegisterGlobalHotKey function as below:<br/> <br/> <div style="color:Black;background-color:White"> <pre>RegisterGlobalHotKey(Keys.Escape, USE_CTRL); RegisterGlobalHotKey(Keys.None, USE_WIN); </pre> </div> <br/> The build is succesfull, but when programm runs I get an error, because the code enters the <em>if (RegisterHotKey(this.Handle, mHotKeyId, modifiers, Convert.ToInt16(hotkey)) == 0)</em> section in the <em>RegisterGlobalHotKey()</em> function.<br/> <br/> My questions are:<br/> 1. Why do I get an error with CTRL+ESC and not with ALT+ESC? How can I disable the Win key using <em>RegisterGlobalHotKey()</em> function call?<br/> 2. Can this function be called, so that 3-key combinations like CTRL+ALT+ESC can also be disabled?<br/> 3. Are there any other hotkeys combinations that exit user from full screen?Sun, 29 Nov 2009 10:23:11 Z2009-11-29T10:23:12Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/e409c813-2633-4416-996c-f06f348f527fhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/e409c813-2633-4416-996c-f06f348f527falainkkkhttp://social.msdn.microsoft.com/Profile/es-ES/?user=alainkkkthis failed in my rowfilter<span style="font-size:x-small"><font size=2> <p>Hi, i tried to perform a rowfilter with datetime below but was told that canot use the convert function in rowfilter.<br/>the date column has the full datetime value e.g. 11/29/2009 5:36:15 PM<br/>i want to perform rowfilter to filter only today date. please advice<br/><br/>dv = operation.SelectAll().DefaultView;<br/>dv.RowFilter =</p> </font></span> <p><span style="font-size:x-small;color:#a31515"><span style="font-size:x-small;color:#a31515">&quot;convert(varchar,Date, 101) = '#&quot;</span></span><span style="font-size:x-small"> + </span><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">DateTime</span></span><span style="font-size:x-small">.Now.ToShortDateString() + </span><span style="font-size:x-small;color:#a31515"><span style="font-size:x-small;color:#a31515">&quot;#' &quot;</span></span><span style="font-size:x-small">;</span></p><hr class="sig">alainSun, 29 Nov 2009 10:07:59 Z2009-11-29T10:26:11Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/58d34bd6-141a-4acc-a7c9-53abcb0a88a8http://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/58d34bd6-141a-4acc-a7c9-53abcb0a88a8code_warriorhttp://social.msdn.microsoft.com/Profile/es-ES/?user=code_warriorI need to intialize an object only once, hwo do i do this?Hi Friend, <br/><br/>I have a default constructor of the class applicant that initializes an and DataAdapter to a table<br/><br/>as:<br/><br/> <div style="color:black;background-color:white"> <pre><span style="color:blue">public</span> <span style="color:blue">class</span> Applicant { tblApplicantsTableAdapter daApplicants; <span style="color:blue">public</span> Applicant() { daApplicants = <span style="color:blue">new</span> tblApplicantsTableAdapter(); } } </pre> </div> In the Applicant class i have a I have MakeInstance method that should create an Applicant object as:<br/><br/> <div style="color:black;background-color:white"> <pre><span style="color:blue">public</span> List&lt;Applicant&gt; MakeInstances(<span style="color:blue">int</span> iInstanceCount) {<br/> List&lt;Applicant&gt; obCollecttion = <span style="color:blue">new</span> List&lt;Applicant&gt;();<br/><span style="color:blue"> for</span>(<span style="color:blue">int</span> i = 1; i &lt;= iInstanceCount; i++) { Applicant appObj = <span style="color:blue">new</span> Applicant(); obCollection.add(appObj); } } </pre> </div> The problem is if i create an object of Applcant using the defualt costructor for each instace it will create an instance dataadapter. But i want each object of applicant class to use only one instance of the dataadapter. How do i do this?<br/><br/>thanksSun, 29 Nov 2009 09:47:32 Z2009-11-29T10:01:23Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/e504a078-4efb-48b5-8872-41228469c5bchttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/e504a078-4efb-48b5-8872-41228469c5bcnemesiscsharphttp://social.msdn.microsoft.com/Profile/es-ES/?user=nemesiscsharpI'ved got to bind the data from my datagridview to textbox.Text, but it seems the application is doing a delay when i select data from datagridview very fast..The problem is there is a delay of sometimes it couldn't catch up what i am selecting. Can someone help me? :)<br/> <br/> Here is my code.<br/> <br/> <pre>if (dataGridViewCustomer.SelectedRows.Count != 0) { textBox1.Text = Convert.ToString( dataGridViewCustomer.SelectedRows[0].Cells[1].Value ); dataGridViewCustomer.Update(); }</pre> Am i missing something? or is this a limitation from c#? hmmSat, 28 Nov 2009 01:30:00 Z2009-11-29T07:25:35Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/0bc5274b-6835-469e-81af-840b5ba37e49http://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/0bc5274b-6835-469e-81af-840b5ba37e49drewdbhttp://social.msdn.microsoft.com/Profile/es-ES/?user=drewdbHow to play incomplete media fileHi,<br/><br/>I'm using BinaryWriter to write a video/audio to disk and want to play the file while it's being written. I have checked that the completed file is working. WMP doesn't seem to want to open it until it final.<br/><br/>This is what i'm doing.<br/><br/> <p><span style="font-size:x-small">fs </span><span style="color:#006400;font-size:x-small"><span style="color:#006400;font-size:x-small">= </span></span><strong><span style="color:#008b8b;font-size:x-small"><span style="color:#008b8b;font-size:x-small">new </span></span><span style="color:#191970;font-size:x-small"><span style="color:#191970;font-size:x-small">FileStream</span></span></strong><span style="color:#006400;font-size:x-small"><span style="color:#006400;font-size:x-small">(</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">@&quot;D:\\tst.avi&quot;</span></span><span style="color:#006400;font-size:x-small"><span style="color:#006400;font-size:x-small">, </span></span><span style="font-size:x-small">FileMode</span><span style="color:#006400;font-size:x-small"><span style="color:#006400;font-size:x-small">.</span></span><span style="font-size:x-small">CreateNew</span><span style="color:#006400;font-size:x-small"><span style="color:#006400;font-size:x-small">, </span></span><span style="font-size:x-small">FileAccess</span><span style="color:#006400;font-size:x-small"><span style="color:#006400;font-size:x-small">.</span></span><span style="font-size:x-small">Write</span><span style="color:#006400;font-size:x-small"><span style="color:#006400;font-size:x-small">, </span></span><span style="font-size:x-small">FileShare</span><span style="color:#006400;font-size:x-small"><span style="color:#006400;font-size:x-small">.</span></span><span style="font-size:x-small">Read</span><span style="color:#006400;font-size:x-small"><span style="color:#006400;font-size:x-small">); <p> </p> <font size=2 color="#006400"><font size=2 color="#006400"> <p> </p> </font></font></span><font size=2 color="#006400"> <p> </p> </font></span></p> <p><span style="font-size:x-small">bw </span><span style="color:#006400;font-size:x-small"><span style="color:#006400;font-size:x-small">= </span></span><strong><span style="color:#008b8b;font-size:x-small"><span style="color:#008b8b;font-size:x-small">new </span></span><span style="color:#191970;font-size:x-small"><span style="color:#191970;font-size:x-small">BinaryWriter</span></span></strong><span style="color:#006400;font-size:x-small"><span style="color:#006400;font-size:x-small">(</span></span><span style="font-size:x-small">fs</span><span style="color:#006400;font-size:x-small"><span style="color:#006400;font-size:x-small">); <p>I've tried waiting for some time but still no luck.<br/><br/>Any help would be great.</p> </span></span></p><hr class="sig">new to .net and c#Sun, 29 Nov 2009 06:35:02 Z2009-11-29T06:35:02Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/16a4cf6e-8140-43b2-a21f-744fc196e25ahttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/16a4cf6e-8140-43b2-a21f-744fc196e25anaturefreak827http://social.msdn.microsoft.com/Profile/es-ES/?user=naturefreak827Problem setting accept button.I am trying to set the accept button on a form that is shown via a public static method. Right now the accept button is always stays at the first of five buttons. <div><br/></div> <div> <pre lang="x-c#"> public static string ShowBox(string txtMessage, string txtTitle) { newMessageBox = new MyMessageBox(); newMessageBox.AcceptButton = newMessageBox.Btn3; newMessageBox.label1.Text = txtMessage; newMessageBox.Text = txtTitle; newMessageBox.ShowDialog(); return Button_id; }</pre> <br/></div>Tue, 24 Nov 2009 21:15:51 Z2009-11-29T05:00:17Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/1cb3d57b-0de1-4d36-8d62-767f144d80echttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/1cb3d57b-0de1-4d36-8d62-767f144d80ecsagarhhttp://social.msdn.microsoft.com/Profile/es-ES/?user=sagarhusing MCI time macros in C# VS2008I am working on building a media player and I need to update a label which shows the current track position. I am using the following command to retrieve the position: <div><br/></div> <div>mciSendString(&quot;status MediaFile length&quot;, media_length, 256, IntPtr.Zero); // where MediaFile is the alias I have used for mpegvideo device</div> <div><br/></div> <div>I am using the following command to retrieve the hour component:</div> <div><br/></div> <div>int hour = MCI_HMS_HOUR(trackLength);</div> <div><br/></div> <div>The error I get is MCI_HMS_HOUR is not in the current context. </div> <div><br/></div> <div><br/></div> <div>Thank you.</div> <div><br/></div> <div><br/></div> <div>Sagar Hatekar</div> <div><br/></div>Sat, 28 Nov 2009 22:40:57 Z2009-11-29T03:02:43Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/59f48b37-8354-4468-93bb-8af9b0d47d84http://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/59f48b37-8354-4468-93bb-8af9b0d47d84soandos3http://social.msdn.microsoft.com/Profile/es-ES/?user=soandos3show the control as it is being dragged and droppedIs it possible to show the control as it is being dragged and dropped?<br/> What I have now is a bare bones drag and drop that redraws the control around the final mouse position.<br/> I tried to change the location property of the control, and that does work, but removes the drag and drop functionality, and cannot cross containers. Is there a solution to show the control as it is being moved?<br/> Thanks.Sun, 29 Nov 2009 01:24:40 Z2009-11-29T02:43:03Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/73af0cb4-3cd9-456f-844b-c05eeaae43c0http://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/73af0cb4-3cd9-456f-844b-c05eeaae43c0Sri096http://social.msdn.microsoft.com/Profile/es-ES/?user=Sri096how to run a X64 bit application from X86 excutable on a X64 machine.Hi,<br/><br/>I am trying to run qwinsta.exe from a X86 Visual Studio project, but every time I search for C:\Windows\System32\qwinsta.exe, app was throwing an exception FileNotFound. I know that the file was searched in C:\Windows\SysWOW64 from a X86 project or 32 bit application. <br/>And more over i didnt find 32 bit version of qwinsta in SysWOW64 folder. <br/><br/>Could somebody help me how could I access the files from System32 folder on X64 machine from a X86 project.  <br/> <br/>Any Project settings that I could change to access these. <br/><br/>The main constraint is I cant build my project with Options set to &quot;Any CPU&quot; or &quot;X64&quot;. I could only build set to &quot;X86&quot;.<br/><br/>Thanks in advance for help.<br/><br/>-Regards,<br/>Sri.<hr class="sig">Thanks, SriSat, 28 Nov 2009 11:18:54 Z2009-11-29T02:35:41Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/954a8ab5-71dd-4a89-8e23-16051c6ef461http://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/954a8ab5-71dd-4a89-8e23-16051c6ef461Gabriel Rotarhttp://social.msdn.microsoft.com/Profile/es-ES/?user=Gabriel%20RotarHow to get aero working with winforms usercontrolls?I have managed to get my form to use aero but I haven't realy found a way to apply aero to my controls, the only information I found was on a codeproject article, and that was using unmanaged c++Sat, 28 Nov 2009 22:24:55 Z2009-11-29T00:19:11Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/cdc20d3b-5d88-4f0f-aa23-e9edd4626f6dhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/cdc20d3b-5d88-4f0f-aa23-e9edd4626f6dayat yassinhttp://social.msdn.microsoft.com/Profile/es-ES/?user=ayat%20yassini don't know where to put this question but pleese answer me ,can we adjust swf file that doesnot have source code????hiii alll<br/> i hope you to answer me ..<br/> <br/> i have swf file but without source code and i  want to hide some writings over it<br/> <br/> do any one have any any idea <br/> ???<br/> <br/> can we change the type if swf file to vedio  so we can adjust it in some way ?????????????????????????<br/> <br/> <br/>Sat, 28 Nov 2009 20:58:57 Z2009-11-28T21:55:50Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/2197983b-2b5b-4044-9f23-ecebb15a3934http://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/2197983b-2b5b-4044-9f23-ecebb15a3934Moksihttp://social.msdn.microsoft.com/Profile/es-ES/?user=MoksiFolder lock in C#I wanted to create folder lock to apply on some of my folders(to hide their contents)  in such a way that I can lock and open them with a password. I read several articles about folder-lock but  had hard time to understand. Is there anybody that can give me a simple <span style="text-decoration:underline"><strong>code</strong> </span> which can help me to uderstand this issue .... I am using C# 2008 express edition.<br/> <br/> thanks.Sun, 22 Nov 2009 00:55:32 Z2009-11-28T21:35:29Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/9377a48c-fc92-4c10-adf9-d86f6ef432cdhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/9377a48c-fc92-4c10-adf9-d86f6ef432cdLetsGoNativehttp://social.msdn.microsoft.com/Profile/es-ES/?user=LetsGoNative? OperatorCan someone explain the following statement to me?<br/><br/><span style="font-size:xx-small"> <p>5 == 1 ? 5</p> </span>Sat, 28 Nov 2009 20:51:42 Z2009-11-28T21:13:00Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/f18d4f80-e3d7-484b-83eb-61cc40f16da7http://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/f18d4f80-e3d7-484b-83eb-61cc40f16da7Varun_Devhttp://social.msdn.microsoft.com/Profile/es-ES/?user=Varun_DevBulk Insert problemHello All<br/><br/>I have been trying to enter multiple records in database . Until now I was trying one by one insertion but I dont think its most efficient way .<br/>What I am doing is : getting all drivers from c:\windows\system32\drivers folder using WMI query.<br/>Here is the code that I am using :<br/><br/> <pre> //Open WMI connection to get Drive info //Build an options object for the connection ConnectionOptions options = new ConnectionOptions(); options.Impersonation = ImpersonationLevel.Impersonate; //Make a connection to a remote computer using these options ManagementScope scope = new ManagementScope(&quot;\\\\&quot; + serverName + &quot;\\root\\cimv2&quot;, options); ObjectQuery driverQuery = new ObjectQuery(&quot;Select * from Win32_SystemDriver where Started='true'&quot;);// ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, driverQuery); ManagementObjectCollection oReturnCollection = searcher.Get(); int count = oReturnCollection.Count; SqlDataAdapter adapter=new SqlDataAdapter(); foreach (ManagementObject driverVar in oReturnCollection) { int driverID = 0; try { collectorConn.Open(); [&quot;PathName&quot;].ToString(); sDriverName = driverVar[&quot;name&quot;].ToString(); sErrorControl = driverVar[&quot;ErrorControl&quot;].ToString(); sStatus = driverVar[&quot;status&quot;].ToString(); sStarted = driverVar[&quot;started&quot;].ToString(); sPathName = driverVar[&quot;PathName&quot;].ToString(); char[] sep = { '\\' }; string[] splitPath = sPathName.Split(sep); int totalSplits = splitPath.Count(); FileVersionInfo fvInfo = null; try { //fvInfo = FileVersionInfo.GetVersionInfo(sPathName); fvInfo = FileVersionInfo.GetVersionInfo(&quot;\\\\&quot; + serverName + &quot;\\C$\\WINDOWS\\system32\\drivers\\&quot; + splitPath[totalSplits-1].ToString()); sDriverVersion = fvInfo.FileVersion.ToString(); } catch { sDriverVersion = &quot;&quot;; } SqlCommand addCmd = new SqlCommand(); addCmd.CommandText = &quot;aut_AddServerDriver&quot;; addCmd.CommandType = CommandType.StoredProcedure; addCmd.Connection = collectorConn; SqlParameter srvidParm = new SqlParameter(&quot;@ServerID&quot;, SqlDbType.Int); srvidParm.Direction = ParameterDirection.Input; srvidParm.Value = serverID; addCmd.Parameters.Add(srvidParm); SqlParameter nameParm = new SqlParameter(&quot;@DriverName&quot;, SqlDbType.VarChar); nameParm.Direction = ParameterDirection.Input; nameParm.Value = checkNull(sDriverName); addCmd.Parameters.Add(nameParm); SqlParameter pathParm = new SqlParameter(&quot;@Path&quot;, SqlDbType.VarChar); pathParm.Direction = ParameterDirection.Input; pathParm.Value = checkNull(sPathName); addCmd.Parameters.Add(pathParm); SqlParameter errorParm = new SqlParameter(&quot;@ErrorControl&quot;, SqlDbType.VarChar); errorParm.Direction = ParameterDirection.Input; errorParm.Value = checkNull(sErrorControl); addCmd.Parameters.Add(errorParm); SqlParameter statusParm = new SqlParameter(&quot;@Status&quot;, SqlDbType.VarChar); statusParm.Direction = ParameterDirection.Input; statusParm.Value = checkNull(sStatus); addCmd.Parameters.Add(statusParm); SqlParameter versionParm = new SqlParameter(&quot;@Version&quot;, SqlDbType.VarChar); versionParm.Direction = ParameterDirection.Input; versionParm.Value = checkNull(sDriverVersion); addCmd.Parameters.Add(versionParm); SqlParameter startedParm = new SqlParameter(&quot;@Started&quot;, SqlDbType.VarChar); startedParm.Direction = ParameterDirection.Input; startedParm.Value = checkNull(sStarted); addCmd.Parameters.Add(startedParm); SqlParameter idParm = new SqlParameter(&quot;@DriverID&quot;, SqlDbType.Int); idParm.Direction = ParameterDirection.Output; addCmd.Parameters.Add(idParm); addCmd.ExecuteNonQuery(); driverID = Convert.ToInt32(addCmd.Parameters[&quot;@DriverID&quot;].Value);</pre> here I am making entry of each driver one by one in database. I was thinking of creating a datatable and making bulkentry of that . Is it good solution. I dont see any improvement.<br/>Here is the changes :<br/><br/> <pre> //Open WMI connection to get Drive info //Build an options object for the connection ConnectionOptions options = new ConnectionOptions(); options.Impersonation = ImpersonationLevel.Impersonate; //Make a connection to a remote computer using these options ManagementScope scope = new ManagementScope(&quot;\\\\&quot; + serverName + &quot;\\root\\cimv2&quot;, options); ObjectQuery driverQuery = new ObjectQuery(&quot;Select * from Win32_SystemDriver where Started='true'&quot;);// ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, driverQuery); ManagementObjectCollection oReturnCollection = searcher.Get(); int count = oReturnCollection.Count; DataTable dt = CreateTable(); SqlDataAdapter adapter=new SqlDataAdapter(); foreach (ManagementObject driverVar in oReturnCollection) { DataRow dr = dt.NewRow(); int driverID = 0; try { collectorConn.Open(); dr[&quot;serverId&quot;] = serverID; dr[&quot;driverName&quot;]=driverVar[&quot;name&quot;].ToString(); dr[&quot;pathName&quot;] = driverVar[&quot;PathName&quot;].ToString(); sPathName = driverVar[&quot;PathName&quot;].ToString(); char[] sep = { '\\' }; string[] splitPath = sPathName.Split(sep); int totalSplits = splitPath.Count(); dr[&quot;ErrorControl&quot;] = driverVar[&quot;ErrorControl&quot;].ToString(); dr[&quot;status&quot;] = driverVar[&quot;status&quot;].ToString(); dr[&quot;started&quot;] = driverVar[&quot;started&quot;].ToString(); FileVersionInfo fvInfo = null; try { //fvInfo = FileVersionInfo.GetVersionInfo(sPathName); fvInfo = FileVersionInfo.GetVersionInfo(&quot;\\\\&quot; + serverName + &quot;\\C$\\WINDOWS\\system32\\drivers\\&quot; + splitPath[totalSplits-1].ToString()); sDriverVersion = fvInfo.FileVersion.ToString(); } catch { sDriverVersion = &quot;&quot;; } dr[&quot;driverVersion&quot;] = sDriverVersion; dt.Rows.Add(dr); } using (SqlBulkCopy copy = new SqlBulkCopy(collectorConn)) { copy.DestinationTableName = &quot;ServerDriver&quot;; copy.WriteToServer(dt); } collectorConn.Close();</pre> Is there any better solution of inserting around 100 records in database using bulcopy or something?<br/><br/>Many thanks for any suggestion!!Fri, 27 Nov 2009 01:03:00 Z2009-11-28T21:05:00Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/8c44089d-39ae-41b3-84f3-02531324e5fehttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/8c44089d-39ae-41b3-84f3-02531324e5feB. Clay Shannonhttp://social.msdn.microsoft.com/Profile/es-ES/?user=B.%20Clay%20ShannonWhat data method to use when returning multiple rows, assigning to a dataset?I know to retreive one value, you use ExecuteScalar, and to perform an action (such as Update or Insert), you use ExecuteNonQuery. What, though, for a Select statement returning (potentially) multiple rows. For example, assigning the result set to a Dataset?<hr class="sig">Writer / Photographer: www.lulu.com/blackbirdcraven, www.bclayshannon.photoshop.comFri, 27 Nov 2009 22:11:20 Z2009-11-28T20:51:10Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/486d530d-50ff-464c-bcc2-3830a161ad56http://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/486d530d-50ff-464c-bcc2-3830a161ad56LetsGoNativehttp://social.msdn.microsoft.com/Profile/es-ES/?user=LetsGoNativeReflectionHow can I use System.Reflection to see what exactly is going on in a class?Sat, 28 Nov 2009 18:13:32 Z2009-11-28T22:05:48Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/3131401f-e68a-44bd-a3fc-f96460fbd357http://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/3131401f-e68a-44bd-a3fc-f96460fbd357SirMoocowhttp://social.msdn.microsoft.com/Profile/es-ES/?user=SirMoocowNetworkStream.Read() is too slow, pauses after each readI'm trying to receive a file that's about 500KB - more than NetworkStream.Read() can read in one go so I'm looping it, but file transfers take ages... I have a label/progressbar that shows the transfer and I can see it transfers a chunk or so fast, then just stops, waits, then transfers another chunk. I have no idea why it's doing this but it's slowing it down ridiculously.<br/> <br/> Here's my code:<br/> <br/> <pre lang="x-c#">packet = new byte[Client.CData[id].dirSize]; while (bytesRead &lt; Client.CData[id].dirSize) { bytesRead += clientStream.Read(packet, bytesRead, Client.CData[id].dirSize - bytesRead); if (Client.CData[id].fFileManager != null) { Client.CData[id].fFileManager.progressStatus.Text = &quot;Received &quot; + bytesRead.ToString() + &quot; of &quot; + Client.CData[id].dirSize.ToString() + &quot; bytes.&quot;; int percentage = (bytesRead * 100 / Client.CData[id].dirSize); Client.CData[id].fFileManager.progressBar.Value = percentage; } }</pre> CData[id].dirSize is the size of the file overall.<br/> <br/> What am I doing wrong?Fri, 27 Nov 2009 23:12:37 Z2009-11-28T19:06:49Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/2e238caf-4ec4-4874-ad83-8c21c839613chttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/2e238caf-4ec4-4874-ad83-8c21c839613cSoniq2http://social.msdn.microsoft.com/Profile/es-ES/?user=Soniq2TFTPI need to transfer data from a laptop to target device via TFTP. <div>I can instruct the target device to begin waiting for my data and now need to just begin sending the data from my side.</div> <div>However, I don't see what class is available in C# for me to implement my side of the TFTP transfer.</div> <div><br/></div> <div>Is there such a class in C#?</div> <div><br/></div> <div>Thanks</div> <div><br/></div> <div>-Mike</div>Thu, 26 Nov 2009 19:55:28 Z2009-11-28T18:58:53Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/930e89a9-ac3f-4500-b33d-73a9da89c90fhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/930e89a9-ac3f-4500-b33d-73a9da89c90fHamid Reza Shojaiehttp://social.msdn.microsoft.com/Profile/es-ES/?user=Hamid%20Reza%20ShojaieBackgroundWorkerHi.<br/>I have a class with a method named  Import() { ... }. This methos is a long time process (reading a database, finding envelopes of some columns and some other computing). In the application main form, I call this method and pass some parameters to it from a void function.<br/>It works perfectly, but when I use the backgroundworker,  this error occured:<br/><br/>Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process.<br/><br/>Please help me.Tue, 24 Nov 2009 21:09:56 Z2009-11-28T18:49:07Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/81569b7b-b917-415d-b2c8-773cd7a41c9ehttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/81569b7b-b917-415d-b2c8-773cd7a41c9eAndy C Chttp://social.msdn.microsoft.com/Profile/es-ES/?user=Andy%20C%20CDelegates and References to classesHi<br/> <br/> If I have the following code:<br/> <br/> <div style="color:Black;background-color:White"> <pre><span style="color:Blue">class</span> A { <br/> <span style="color:Blue">public</span> A(Action&lt;<span style="color:Blue">int</span> &gt; myDelegate) { MyDelegate = myDelegate; } Action&lt;<span style="color:Blue">int</span> &gt; MyDelegate {<span style="color:Blue">get</span> ; <span style="color:Blue">private</span> s<span style="color:Blue">et</span> ;} } <span style="color:Blue"><br/> class</span> B { <br/> <span style="color:Blue">public</span> B(Action&lt;<span style="color:Blue">int</span> &gt; myDelegate) { MyDelegate = myDelegate; } Action&lt;<span style="color:Blue">int</span> &gt; MyDelegate {<span style="color:Blue">get</span> ; <span style="color:Blue">private</span> <span style="color:Blue">set</span> ;} }</pre> </div> <br/> If I do:<br/> <br/> <div style="color:Black;background-color:White"> <pre> Action&lt;<span style="color:Blue">int</span> &gt; action = i =&gt; DoSomething(i); A = <span style="color:Blue">new</span> A(action); B = <span style="color:Blue">new</span> B(A.MyDelegate); </pre> </div> <br/> Will the class B be created with the reference to the underlying delegate or will it keep a reference to class A? As if it keeps a reference to class A and I want class A to be garbage collected it could create a memory leak as long as B is alive.<br/> <br/> Thank youSat, 28 Nov 2009 18:39:12 Z2009-11-28T18:39:13Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/b0d45d3b-e364-4166-8cf1-2534ef66ccb0http://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/b0d45d3b-e364-4166-8cf1-2534ef66ccb0MDMourahttp://social.msdn.microsoft.com/Profile/es-ES/?user=MDMouraBase64 and Byte ConversionHello,<br/> <br/> I have the following:<br/> String result = Convert.ToBase64String(Encoding.UTF8.GetBytes(&quot;Test&quot;));<br/> <br/> Shouldn't result become &quot;Test&quot;? I get &quot;VGVzdA==&quot;<br/> <br/> I am using this approach to save Byte data into a XML file and get it back to a string.<br/> It isn't working so I made this test and I was expecting to get &quot;Test&quot; in result.<br/> <br/> Thanks,<br/> Miguel<br/>Sat, 28 Nov 2009 02:11:44 Z2009-11-28T18:37:38Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/60ac26df-a6d0-47fc-ac1e-30f431dc8f6chttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/60ac26df-a6d0-47fc-ac1e-30f431dc8f6ccode_warriorhttp://social.msdn.microsoft.com/Profile/es-ES/?user=code_warriorHow to i Converty Object to Image?hi Friend, <br/><br/><br/>I need to convert an Object to Image type, but in which namespace / reference type &quot;Image&quot; resides?<br/><br/>thanksSat, 28 Nov 2009 17:19:13 Z2009-11-28T17:54:51Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/0e9d931a-fb35-44ca-bd60-adac003b82d9http://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/0e9d931a-fb35-44ca-bd60-adac003b82d9jal2http://social.msdn.microsoft.com/Profile/es-ES/?user=jal2Late-Binding problem I'm trying to convert the following VB.Net code to C#<br/> <br/> <br/> Dim DB As DAO.Database = New DAO.DBEngine().OpenDatabase(&quot;C:\Northwind.mdb&quot;)<br/>         Dim td As DAO.TableDef = DB.TableDefs(&quot;Customers&quot;)<br/>         For Each idx As DAO.Index In td.Indexes<br/>             If idx.Primary Then<br/>                 For i As Int32 = 0 To idx.Fields.Count - 1<br/>                     MsgBox(idx.Fields(i).Name)<br/>                 Next<br/>             End If<br/>         Next<br/> <br/> The problem is in the line <br/> .......For i As Int32 = 0 To idx.Fields.Count - 1<br/> The property &quot;Count&quot; doesn't show up in Intellisense  (neither in VB.Net or C#). In fact you can't even write, in C#,<br/> ......MsgBox(idx.Fields(i).Name)<br/> because &quot;Fields&quot; shows up as a single object, not as an array or collection of fields.  Yet in VB.Net I can get away with all this, apparently because it does late-binding automatically. In C# I tried the following (to at least access the &quot;Count&quot; value even though this still falls short of accessing the &quot;Name&quot; value):<br/> <br/>  DAO.TableDef TD = CurrentDB.TableDefs[oTab.Table];<br/>             foreach (DAO.Index idx in TD.Indexes)<br/>                 if (idx.Primary)<br/>                 {<br/>                     Type oType = idx.Fields.GetType();<br/>                     System.Reflection.PropertyInfo pi = oType.GetProperty(&quot;Count&quot;);<br/>                     int Count = (int)pi.GetValue(idx.Fields, null);<br/>                 }<br/> <br/> But &quot;pi&quot; comes out &quot;null&quot;. So I can't even get the Count value, much less the Name values (which is what I really need). Any ideas? (If you want to try this yourself, please add a reference to Microsoft DAO 3.6 Object Library).  Thanks for any help !<br/>Sat, 28 Nov 2009 15:51:07 Z2009-11-28T17:53:29Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/dad8f9e8-dcf3-46d6-9640-63cd5b7c2eb7http://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/dad8f9e8-dcf3-46d6-9640-63cd5b7c2eb7code_warriorhttp://social.msdn.microsoft.com/Profile/es-ES/?user=code_warriorHow to convert an object to byte[ ]?Hi Friend, <br/><br/>I dont think i;ve written the thread in an understandable way....actually i need to convert a value in a datarow cell that of type varbinary(in DB) to byte[]?<br/><br/><br/>thanksSat, 28 Nov 2009 15:50:37 Z2009-11-28T16:57:56Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/9f2d7e8e-4dc0-46a0-a720-b8e74d508285http://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/9f2d7e8e-4dc0-46a0-a720-b8e74d508285neetu singh 123http://social.msdn.microsoft.com/Profile/es-ES/?user=neetu%20singh%20123C#how we can write a program for drawing pyramid using for loop in c sharp?<br/>Sat, 28 Nov 2009 16:07:44 Z2009-11-28T16:24:07Zhttp://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/d5620fc7-6fbf-48e0-9140-3914747221c0http://social.msdn.microsoft.com/Forums/es-ES/csharpgeneral/thread/d5620fc7-6fbf-48e0-9140-3914747221c0Boki_thegamehttp://social.msdn.microsoft.com/Profile/es-ES/?user=Boki_thegameFrom picturebox to databaseHow to put image from picturebox to database using Linq???<br/> <br/> ThanksSat, 28 Nov 2009 01:17:53 Z2009-11-28T16:21:01Z