c#-2.0

.NET NetworkStream Read slowness

强颜欢笑 提交于 2019-12-05 06:45:14
问题 I've got some network code to process an arbitary TCP connection. It all seems to work as expected but seems slow. When i've profiled the code the it seems to spend a good 600 ms in NetworkStream.Read() and I'm wondering how to improve it. I've fiddled with the buffer sizes and alternated between a massive buffer to read all of the data in one go or a small one which should concatenate the data into a StringBuilder. Currently the client i'm using is a web-browser but this code is generic and

Convert array of enum values to bit-flag combination

不羁的心 提交于 2019-12-05 03:26:15
How to create a bit-flag combination from an array of enum values in the simplest most optimal way in C# 2.0. I have actually figured out a solution but I am just not satisfied with the complexity here. enum MyEnum { Apple = 0, Apricot = 1, Breadfruit = 2, Banana = 4 } private int ConvertToBitFlags(MyEnum[] flags) { string strFlags = string.Empty; foreach (MyEnum f in flags) { strFlags += strFlags == string.Empty ? Enum.GetName(typeof(MyEnum), f) : "," + Enum.GetName(typeof(MyEnum), f); } return (int)Enum.Parse(typeof(MyEnum), strFlags); } int result = 0; foreach (MyEnum f in flags) { result |

Youtube C# .NET API : Uploading video and getting events when finished

淺唱寂寞╮ 提交于 2019-12-05 01:36:05
问题 This is the code to upload a video to Youtube using the C# .NET API from a Windows Forms desktop application: YouTubeRequestSettings settings = new YouTubeRequestSettings("whatwill come here ?", "my api key", "my youtube login email", "my youtube login password"); YouTubeRequest request = new YouTubeRequest(settings); Video newVideo = new Video(); newVideo.Title = "test 1"; newVideo.Tags.Add(new MediaCategory("Gaming", YouTubeNameTable.CategorySchema)); newVideo.Keywords = "test 1 , test 2";

How to read an .XLSX (Excel 2007) file using ADO.NET? I am finding “Could not find installable ISAM”-error

蓝咒 提交于 2019-12-05 00:37:08
问题 I need to work in .net 2.0 . So I can't use OpenXML. This is my source code and I have already Installed AccessDatabaseEngine.exe . But still getting the exception: "Could not find installable ISAM". I have also tried "Extended Properties=Excel 8.0" in the connection string. static void Main(string[] args) { DataSet dataSet = new DataSet(); OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|Data Directory|\HSC.xlsx;Extended Properties=Excel 12.0

Unable to call Dispose?

。_饼干妹妹 提交于 2019-12-05 00:27:12
This one has confused me a little... Attempting to dispose of an XmlReader XmlReader reader = XmlReader.Create(filePath); reader.Dispose(); Provides the following error: 'System.Xml.XmlReader.Dispose(bool)' is inaccessible due to its protection level however the following is fine: using(XmlReader reader = XmlReader.Create(filePath)) { } When I look at the definition in Reflector I can't understand why I can't call Dispose Implementation of Dispose: Can anyone point out what I'm missing? The problem is that XmlReader uses explicit interface implementation to implement IDisposable . So you can

Get icon 128*128 File type C#

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 22:02:45
I need to get the icon of a file type doc or txt It's size should be 128*128 and be saved as an png or ico file in good quality. I used Icon ico = Icon.ExtractAssociatedIcon(@"d:\\1.txt"); pictureBox1.Image = ico.ToBitmap(); and save the image from the pictureBox1, but that size is 32*32. I really want a size 128*128. How can I do that? rene There is no icon-size 128x128 available from the Shell API SHGetImageList . The sizes range from the Win95 era of 16x16 and 32x32 via XP's 48x48 and finally Vista that added the 256x256 size. To get a png file from any of the available icon sizes I

Get Proxy configuration before accessing an external webservice (.NET 2.0)

非 Y 不嫁゛ 提交于 2019-12-04 19:13:55
When trying to invoke a method on an external webservice (over the Internet) it throws me "The remote server returned an error: (407) Proxy Authentication Required." To solve this, I used the following code to set the proxy we use in the office: //Set the system proxy with valid server address or IP and port. System.Net.WebProxy pry = new System.Net.WebProxy("MyHost", 8080); //The DefaultCredentials automically get username and password. pry.Credentials = System.Net.CredentialCache.DefaultCredentials; System.Net.WebRequest.DefaultWebProxy = pry; That works fine, but now... I need to do that

To check whether the string value has numeric value or not in C#

老子叫甜甜 提交于 2019-12-04 17:59:12
问题 I am having an string like this string str = "dfdsfdsf8fdfdfd9dfdfd4" I need to check whether the string contains number by looping through the array. 回答1: What about a regular expression: bool val = System.Text.RegularExpressions.Regex.IsMatch(str, @"\d"); 回答2: If you are looking for an integer value you could use int.TryParse : int result; if (int.TryParse("123", out result)) { Debug.WriteLine("Valid integer: " + result); } else { Debug.WriteLine("Not a valid integer"); } For checking a

.net - Glass effect in C# 2.0 applications

不打扰是莪最后的温柔 提交于 2019-12-04 15:47:47
How can I give a Vista or Mac OS X style glass effects on windows forms applications in .net 2.0? This is done using interop with the Vista DWM (Desktop Window Manager) API. For example, import these functions: [DllImport("dwmapi.dll")] static extern void DwmExtendFrameIntoClientArea(IntPtr hWnd, ref Margins pMargins); [StructLayout(LayoutKind.Sequential)] struct Margins { public int cxLeftWidth; public int cxRightWidth; public int cyTopHeight; public int cyBottomHeight; } Then you can use this to "pull down" glass from the top of the window down into the client area: GlassMargins.Top = 40;

Changing the row height of a datagridview

痴心易碎 提交于 2019-12-04 15:07:55
问题 How can I change the row height of a DataGridView? i set the value for the property but height doesnt changed,anyother property has to be checked before set this one 回答1: You need to set the Height property of the RowTemplate: var dgv = new DataGridView(); dgv.RowTemplate.Height = 30; 回答2: You can set the row height by code dataGridView.RowTemplate.Height = 35; or by property panel 回答3: Try datagridview.RowTemplate.MinimumHeight = 25;//25 is height. I did that and it worked fine! 回答4: you can