c#-2.0

End of Stream encountered before parsing was completed?

橙三吉。 提交于 2019-11-29 00:54:52
I am trying to deserialize a stream but I always get this error "End of Stream encountered before parsing was completed"? Here is the code: //Some code here BinaryFormatter b = new BinaryFormatter(); return (myObject)b.Deserialize(s);//s---> is a Stream object that has been fill up with data some line over here Any one have ideas? Try to set the position to 0 of your stream and do not use your object but the object type. BinaryFormatter b = new BinaryFormatter(); s.Position = 0; return (YourObjectType)b.Deserialize(s); Make sure the serialization completed, and that the serialization type

Faking browser request in ASP.net C#

泄露秘密 提交于 2019-11-29 00:06:44
I'm using the code below to pull one of our 3rd party developed pages in so I can parse it as XML for my random bits of work. Irritatingly we stil have a browser detection level set on the server that only allows certain browsers on to the site; so the question is how would I fake it so that the server thinks its a browser request? static string GetHtmlPage(string strURL) { String strResult; System.Net.WebResponse objResponse; System.Net.WebRequest objRequest = System.Net.HttpWebRequest.Create(strURL); objResponse = objRequest.GetResponse(); using (System.IO.StreamReader sr = new System.IO

Speed up File.Exists for non existing network shares

﹥>﹥吖頭↗ 提交于 2019-11-28 21:06:47
I have to check if a set of file paths represent an existing file. It works fine except when the path contains a network share on a machine that's not on the current network. In this case it takes a pretty long time (30 or 60 seconds) to timeout. Questions Is there a way to shorten the timeout for non existing network shares? (I'm certain that when they do exist they'll answer quickly, so a timeout of 1 sec would be fine) Is there any other way to solve this issue without starting to cache and making the algorithm more complex? (ie, I already know these X network shares don't exist, skip the

ExecuteNonQuery requires the command to have a transaction error in my code

旧城冷巷雨未停 提交于 2019-11-28 20:03:53
I get the following error on cmd.ExecuteNonQuery . "ExecuteNonQuery requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized." Here is my code: //if (hdRefresh.Value.Length > done.Value.Length || done.Value == "1") //{ // //Write Your Add Customer Code here > Response.Write("true") // done.Value = hdRefresh.Value; //} //else //{ // Response.Redirect("~/Cashier/BTBill.aspx"); // return; //} if (IsClosedToDay()) { ScriptManager.RegisterClientScriptBlock(Page, typeof

List of new features in C# 2.0, 3.0 and 4.0 [closed]

限于喜欢 提交于 2019-11-28 19:41:20
I worked on the .NET 1.1 project for a long time, and I was stuck at C# 1.0 and now I would like to catch up with the latest and greatest. Google returned a lot of information on new features in C# v2.0, but for the versions 3 and 4 I found only partial information. Is there somewhere on the Internet some list of all new features introduced in C# in v2.0, v3.0 and v4.0? Complete plug for my own book, but hopefully not gratuitous: get hold of the early access version of the second edition of C# in Depth . It skips C# 1, but goes into detail on every feature of C# 2, 3 and 4. If you just want a

How to write to the stdin of another app?

旧时模样 提交于 2019-11-28 11:21:05
I have a module that reads the StandardError of a process. Everything works fine, but I want to do something different. I don't know how to redirect stdin like the native way: app1.exe -someargs | app2.exe -someargs Where app2 reads all the stdout of app1 in its stdin. Have a look at the MSDN reference documentation for the following (both to be found in the System.Diagnostics namespace): Process.StandardInput ProcessStartInfo.RedirectStandardInput . There's an example showing how to start a child process and write directly to its standard input. For your particular example, here's how you set

How to programmatically minimize opened window folders

扶醉桌前 提交于 2019-11-28 10:57:52
How can I get the list of opened of folders, enumerate through it and minimize each folder programmatically? At times some opened folders do steal focus from the tool when jumping from one form in the application to another. Preventing this is of high priority for our client. The customers are visually impaired people, so they access the machine only via screen readers. Minimizing other windows (folders) is not at all a problem, in fact a requirement. I tried this: foreach (Process p in Process.GetProcessesByName("explorer")) { p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized; } As

How to change System.Windows.Forms.ToolStripButton highlight/background color when checked?

回眸只為那壹抹淺笑 提交于 2019-11-28 09:42:55
I have a ToolStripButton that is used as a radio button. When it is checked, a blue outline surrounds the button, but there is no background color. It is not clear enough for the user that the button is checked, so I would like to change the background color to make the check state more visible. How do I go about changing the highlight color when the Checked property is set to true? Here is a code snippet: this.hideInactiveVehiclesToolstripButton.CheckOnClick = true; this.hideInactiveVehiclesToolstripButton.ForeColor = System.Drawing.Color.Blue; this.hideInactiveVehiclesToolstripButton

Are event subscribers called in order of subscription?

一个人想着一个人 提交于 2019-11-28 09:39:42
Is it safe to assume that event subscribers are called in order of subscription? Example: void One(object sender, EventArgs e) {} void Two(object sender, EventArgs e) {} event EventHandler foo; foo += One; foo += Two; Is One() always called before Two() when the event is fired? Edit: You should ofcourse not rely on it, I was just thinking. The idea was, that multicast delegates are similary to the COMMAND pattern. So I was just wondering. Ususally you would use a collection that keeps the order for COMMANDs so you can do undo/redo/whatever. Jon Skeet Given that implementation, yes, they will

How to execute a .bat file from a C# windows form app?

a 夏天 提交于 2019-11-28 07:13:25
问题 What I need to do is have a C# 2005 GUI app call a .bat and several VBScript files at user's request. This is just a stop-gap solution until the end of the holidays and I can write it all in C#. I can get the VBScript files to execute with no problem but I am unable to execute the .bat file. When I "click" in the C# app to execute the .bat file a DOS window opens up and closes very fast and the test .bat file does not execute - "Windows does not recognize bat as an internal or external