c#-2.0

End of Stream encountered before parsing was completed?

我怕爱的太早我们不能终老 提交于 2019-11-26 16:39:18
问题 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? 回答1: 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

C# ASP.NET Send Email via TLS

别说谁变了你拦得住时间么 提交于 2019-11-26 16:19:53
问题 In order to comply with HIPAA regulations, we need to send email from an external site (outside the firewall) to an internal Exchange server (inside the firewall). Our Exchange admins tell us we need to use TLS encryption to send mail from the web server to the email server. I've never used TLS before and I'm not very familiar with it. Searching on Google as brought up numerous paid-for-use libraries. Is there anything native to .NET that will accomplish this? If so, how do I configure it? If

How to ignore a certificate error with c# 2.0 WebClient - without the certificate

末鹿安然 提交于 2019-11-26 10:34:29
问题 Using Visual Studio 2005 - C# 2.0, System.Net.WebClient.UploadData(Uri address, byte[] data) Windows Server 2003 So here\'s a stripped down version of the code: static string SO_method(String fullRequestString) { string theUriStringToUse = @\"https://10.10.10.10:443\"; // populated with real endpoint IP:port string proxyAddressAndPort = @\"http://10.10.10.10:80/\"; // populated with a real proxy IP:port Byte[] utf8EncodedResponse; // for the return data in utf8 string responseString; // for

Convert array of strings to List<string>

喜你入骨 提交于 2019-11-26 10:22:32
问题 I\'ve seen examples of this done using .ToList() on array types, this seems to be available only in .Net 3.5+. I\'m working with .NET Framework 2.0 on an ASP.NET project that can\'t be upgraded at this time, so I was wondering: is there another solution? One that is more elegant than looping through the array and adding each element to this List (which is no problem; I\'m just wondering if there is a better solution for learning purposes)? string[] arr = { \"Alpha\", \"Beta\", \"Gamma\" };

How to use WebBrowser control DocumentCompleted event in C#?

风格不统一 提交于 2019-11-26 09:00:37
问题 Before starting writing this question, i was trying to solve following // 1. navigate to page // 2. wait until page is downloaded // 3. read and write some data from/to iframe // 4. submit (post) form The problem was, that if a iframe exists on a web page, DocumentCompleted event would get fired more then once (after each document has been completed). It was highly likely that program would have tried to read data from DOM that was not completed and naturally - fail. But suddenly while

how to highlight a text or word in a pdf file using iTextsharp?

吃可爱长大的小学妹 提交于 2019-11-26 08:26:44
问题 I need to search a word in a existing pdf file and i want to highlight the text or word and save the pdf file I have an idea using PdfAnnotation.CreateMarkup we could find the position of the text and we can add bgcolor to it...but i dont know how to implement it :( Please help me out 回答1: This is one of those "sounds easy but is actually really complicated" things. See Mark's posts here and here. Ultimately you'll probably be pointed to LocationTextExtractionStrategy. Good luck! If you

C#: multiline text in DataGridView control

馋奶兔 提交于 2019-11-26 07:46:39
问题 Is it possible for the DataGridView control to display multiline text in a cell? I am using Visual Studio 2005 and C#. 回答1: You should set DefaultCellStyle.WrapMode property of column to DataGridViewTriState.True . After that text in cells will be displayed correctly. Example ( DataGridView with one column): dataGridView1.Columns[0].DefaultCellStyle.WrapMode = DataGridViewTriState.True; dataGridView1.Rows.Add("test" + Environment.NewLine + "test"); ( Environment.NewLine = \r\n in Windows) 回答2

How can I evaluate C# code dynamically?

五迷三道 提交于 2019-11-26 01:20:02
问题 I can do an eval(\"something()\"); to execute the code dynamically in JavaScript. Is there a way for me to do the same thing in C#? An example of what I am trying to do is: I have an integer variable (say i ) and I have multiple properties by the names: \"Property1\", \"Property2\", \"Property3\", etc. Now, I want to perform some operations on the \" Property i \" property depending on the value of i . This is really simple with Javascript. Is there any way to do this with C#? 回答1: