Fórmulas e Cenas

Object Reference Not Set to Instance of an Object

  Home  |   Contact  |   Syndication    |   Login
  39 Posts | 0 Stories | 6 Comments | 0 Trackbacks

News

Archives

Post Categories

Links

C#

If you have a "{" or "}" inside a string when using string.format you will get the error mentioned in the title. To fix this you must double the charater. Error Example: string teste = string.Format(" This is a {teste} {0} ", mystring); Correct Example: string teste = string.Format(" This is a {{teste}} {0} ", mystring);v...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

<script type="text/javascript" language="javascript"> Sys.WebForms.PageRequestMan... function refresh() { //Your code here; } </script> Source
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

FileInfo fileInf = new FileInfo("c:\myfile.txt"); FtpWebRequest reqFTP = (FtpWebRequest)FtpWebReques... Uri("ftp://myFTPSite/myfile... reqFTP.Credentials = new NetworkCredential("myUser",... "myFTPDomain"); reqFTP.KeepAlive = false; reqFTP.Method = WebRequestMethods.Ftp.Uploa... reqFTP.UseBinary = true; reqFTP.ContentLength = fileInf.Length; int buffLength = 2048; byte[] buff = new byte[buffLength]; int contentLen; FileStream fs = fileInf.OpenRead(); try { Stream strm =...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

FileStream outputStream = new FileStream("c:\myfilefolder... FtpWebRequest reqFTP = (FtpWebRequest)FtpWebReques... Uri("ftp://myFTPSite/file.t... reqFTP.Method = WebRequestMethods.Ftp.Downl... reqFTP.UseBinary = true; reqFTP.Credentials = new NetworkCredential("myUser",... FtpWebResponse response = (FtpWebResponse)reqFTP.GetR... Stream ftpStream = response.GetResponseStream(); int bufferSize = 2048; int readCount; byte[] buffer = new byte[bufferSize];...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

FtpWebRequest reqFTP = (FtpWebRequest)FtpWebReques... Uri("ftp://myFTPURL/")); reqFTP.UseBinary = true; reqFTP.Credentials = new NetworkCredential("myUser", "myPassword", "FTPDomain"); reqFTP.Method = WebRequestMethods.Ftp.ListD... WebResponse response = reqFTP.GetResponse(); StreamReader reader = new StreamReader(response.GetRe... string line = reader.ReadLine(); while (line != null) { line = reader.ReadLine(); } reader.Close(); response.Close(); Enjoy :)...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

The scenario: Imagine someone asks you to create an XML file with some data structure. The approuch: There are several ways to achieve this, the fastest and less time comsuming is to create a class structure that represents the XML structure you need, fill in with the data and them serialize it to a string and save it to a file. The Implementation: Lets say you need a single node, followed by an array of nodes. Class Definition: public class MyNode { [XmlElementAttribute("code")] public int code;...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Occasionally an application that I am working on throws the above error... After trying to fix my code for a bit, and not finding the problem I googled a bit and discovered that this error is caused by a windows service that must be running. So, if you ever encounter this error, you must turn on the 'Distributed Transaction Coordinator' in order to solve it. Hope this helps. Original source: http://geekswithblogs.net/n...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Type myType = typeof(MyClass); string methodName = "methodNameAsString"; MethodInfo myTypeGetMethod = myType.GetMethod(methodName); MyClass obj = new MyClass(); object[] parms = { 123, "string test"}; myTypeGetMethod.Invoke(obj, args);
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Well... I cant really express my feelings for this kind of programming... The WTF way: DateTime myNewDate = DateTime.Parse((myOldDate.Year - 1).ToString() + "-" + myOldDate.Month.ToString() + "-" + myOldDate.Day.ToString()); The right way: DateTime myNewDate = myOldDate.Date.AddYears(-1);
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Well, this one i simply cannot understand... why anyone would do +0 after and int.parse. Any Ideas? int myVar = Int32.Parse(ConfigurationMa... + "") + 0;
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Full C# Archive