Archive for April, 2011

windows-mobile-phone

Not enough storage is available to complete this operation

0

http://msdn.microsoft.com/en-us/library/ms681382%28VS.85%29.aspx

ERROR_OUTOFMEMORY 14 (0xE) – Not enough storage is available to complete this operation.

 

.NET

Consider using System.IO.Path.Combine() instead of string concatenation

0

http://dotnettipoftheday.org/tips/SystemIOPathCombine.aspx

Let’s review the following code for creating a file path:

    public string GetFullPath(string fileName)
    {
        string folder = ConfigurationManager.AppSettings["MyFolder"];
        return folder + fileName;
    }

This code is prone to error. For example, when you set the folder setting, you have to remember to make sure it ends with a slash. To avoid such problems use Path.Combine() method which will ensure that the folder has ending slash:

    public string GetFullPath(string filename)
    {
        string folder = ConfigurationManager.AppSettings["MyFolder"];
        return Path.Combine(folder, filename);
    }
.NET

Use Path.GetRandomFileName() or Path.GetTempFileName() when working with temp files

0

http://dotnettipoftheday.org/tips/PathGetRandomFileName.aspx

 

Do not reinvent function for generating unique name for temporary files. Use one of the existing methods:

.NET

?? operator (C#)

0

http://dotnettipoftheday.org/tips/double_question_mark_operator_cs.aspx

 

The ?? operator returns the left-hand operand if it is not null, or else it returns the right operand. For example:

int? x = null;

...

// y = x, unless x is null, in which case y = -1.

int y = x ?? -1;

The ?? operator also works with reference types:

//message = param, unless param is null
//in which case message = "No message"
string message = param ?? "No message";
.NET

Speed testing in .NET – System.Diagnostics.Stopwatch

0

http://dotnettipoftheday.org/tips/system_diagnostics_stopwatch.aspx

System.Diagnostics.Stopwatch is a replacement for what most people probably do to identify the time spent on excecuting a method. The process usually goes something like: create a DateTime.Now value at the start and then subtract the ending DateTime.Now to get the TimeDuration value that elapsed.

As an alternative, the Stopwatch class was built using low-level API calls, with less overhead than other .NET methods. If the hardware and Windows version of the computer support a high-resolution performance counter, it will use this counter instead of the standard PC clock.

Here is a simple example:

More >

SQL Server

COALESCE function instead of long CASE WHEN … ELSE (T-SQL)

0

Instead of using long “SELECT … CASE WHEN … ELSE …” construction, you can use the COALESCE function when you need to find a value that is not NULL. Lets review the following T-SQL expression, in which we need to select an available “source”:

http://dotnettipoftheday.org/tips/sql-coalesce.aspx

SELECT TheSource =
   CASE
      WHEN localSource IS NOT NULL THEN localSource
      WHEN intranetSource IS NOT NULL THEN intranetSource
      WHEN internetSource IS NOT NULL THEN internetSource
      ELSE ''
   END
FROM ...

Now lets rewrite the code above using COALESCE function:


SELECT

More >

.NET

Correct event invocation

0

http://dotnettipoftheday.org/tips/correct-event-invocation.aspx

Be aware that if there are no subscribers a .NET event will be null. Therefore when raising the event from C# test it for null first.


    public event EventHandler SelectedNodeChanged;

    protected virtual void OnSelectedNodeChanged(object sender, EventArgs e)
    {
        //Event will be null if there are no subscribers
        if (SelectedNodeChanged != null)
        {
            SelectedNodeChanged(this, e);
        }
    }

However in multithreaded application the last subscriber can unsubscribe immediately after the null check and before the event is raised. To avoid a null reference exception make a temporary copy of the event.

More >

.NET

C# Tips & Tricks

0

 

Office

Keyboard shortcuts for Word

0
   Command Name                  Shortcut Keys
   ------------------------------------------------------------------------

   All Caps                      CTRL+SHIFT+A
   Annotation                    ALT+CTRL+M
   App Maximize                  ALT+F10
   App Restore                   ALT+F5
   Apply Heading1                ALT+CTRL+1
   Apply Heading2                ALT+CTRL+2
   Apply Heading3                ALT+CTRL+3
   Apply List Bullet             CTRL+SHIFT+L
   Auto Format                   ALT+CTRL+K
   Auto Text                     F3 or ALT+CTRL+V
   Bold                          CTRL+B or CTRL+SHIFT+B
   Bookmark                      CTRL+SHIFT+F5
   Browse Next                   CTRL+PAGE DOWN
   Browse Previous               CTRL+PAGE UP
   Browse Sel                    ALT+CTRL+HOME
   Cancel                        ESC
   Center Para                   CTRL+E
   Change Case                   SHIFT+F3
   Char Left                     LEFT
   Char Left Extend              SHIFT+LEFT
   Char Right                    RIGHT
   Char Right Extend             SHIFT+RIGHT
   Clear                         DELETE
   Close or Exit                 ALT+F4
   Close Pane                    ALT+SHIFT+C
   Column Break                  CTRL+SHIFT+ENTER
   Column Select                 CTRL+SHIFT+F8
   Copy                          CTRL+C or CTRL+INSERT
   Copy Format                   CTRL+SHIFT+C
   Copy

More >

SQL Server

SQL Server Date Formats

0
Standard Date Formats Date Format Standard SQL Statement Sample Output Mon DD YYYY 1 HH:MIAM (or PM) Default SELECT CONVERT(VARCHAR(20), GETDATE(), 100) Jan 1 2005 1:29PM 1 MM/DD/YY USA SELECT CONVERT(VARCHAR(8), GETDATE(), 1) AS [MM/DD/YY] 11/23/98 MM/DD/YYYY USA SELECT CONVERT(VARCHAR(10), GETDATE(), 101) AS [MM/DD/YYYY] 11/23/1998 YY.MM.DD ANSI SELECT CONVERT(VARCHAR(8), GETDATE(), 2) AS [YY.MM.DD] 72.01.01 YYYY.MM.DD ANSI SELECT CONVERT(VARCHAR(10), GETDATE(), 102) AS [YYYY.MM.DD] 1972.01.01 DD/MM/YY British/French SELECT CONVERT(VARCHAR(8), GETDATE(), 3) AS [DD/MM/YY] 19/02/72 DD/MM/YYYY British/French SELECT CONVERT(VARCHAR(10), GETDATE(), 103) AS [DD/MM/YYYY] 19/02/1972 DD.MM.YY German SELECT CONVERT(VARCHAR(8), GETDATE(), 4) AS [DD.MM.YY] 25.12.05 DD.MM.YYYY German SELECT CONVERT(VARCHAR(10), GETDATE(), 104) AS [DD.MM.YYYY] 25.12.2005

More >

Go to Top