Monday, July 29, 2013

datetime convertions c#

This example shows how to format DateTime using String.Format method. All formatting can be done also using DateTime.ToString method.
Custom DateTime Formatting

There are following custom format specifiers y (year), M (month), d (day), h (hour 12), H (hour 24), m (minute), s (second), f (second fraction), F (second fraction, trailing zeroes are trimmed), t (P.M or A.M) and z (time zone).

Following examples demonstrate how are the format specifiers rewritten to the output.



// create date time 2008-03-09 16:05:07.123
DateTime dt = new DateTime(2008, 3, 9, 16, 5, 7, 123);

String.Format("{0:y yy yyy yyyy}", dt); // "8 08 008 2008" year
String.Format("{0:M MM MMM MMMM}", dt); // "3 03 Mar March" month
String.Format("{0:d dd ddd dddd}", dt); // "9 09 Sun Sunday" day
String.Format("{0:h hh H HH}", dt); // "4 04 16 16" hour 12/24
String.Format("{0:m mm}", dt); // "5 05" minute
String.Format("{0:s ss}", dt); // "7 07" second
String.Format("{0:f ff fff ffff}", dt); // "1 12 123 1230" sec.fraction
String.Format("{0:F FF FFF FFFF}", dt); // "1 12 123 123" without zeroes
String.Format("{0:t tt}", dt); // "P PM" A.M. or P.M.
String.Format("{0:z zz zzz}", dt); // "-6 -06 -06:00" time zone




You can use also date separator / (slash) and time sepatator : (colon). These characters will be rewritten to characters defined in the current DateTimeForma­tInfo.DateSepa­rator and DateTimeForma­tInfo.TimeSepa­rator.

// date separator in german culture is "." (so "/" changes to ".")
String.Format("{0:d/M/yyyy HH:mm:ss}", dt); // "9/3/2008 16:05:07" - english (en-US)
String.Format("{0:d/M/yyyy HH:mm:ss}", dt); // "9.3.2008 16:05:07" - german (de-DE)

Here are some examples of custom date and time formatting:

// month/day numbers without/with leading zeroes
String.Format("{0:M/d/yyyy}", dt); // "3/9/2008"
String.Format("{0:MM/dd/yyyy}", dt); // "03/09/2008"

// day/month names
String.Format("{0:ddd, MMM d, yyyy}", dt); // "Sun, Mar 9, 2008"
String.Format("{0:dddd, MMMM d, yyyy}", dt); // "Sunday, March 9, 2008"

// two/four digit year
String.Format("{0:MM/dd/yy}", dt); // "03/09/08"
String.Format("{0:MM/dd/yyyy}", dt); // "03/09/2008"

Reference http://www.csharp-examples.net/string-format-datetime/

Saturday, July 6, 2013

List all WorkSpaces in TFS, Removing TFS workspaces from old users or old computers

to list all the workspaces

c:\projects>tf workspaces /owner:* /computer:*


When working with Microsoft Team Foundation Server, sometimes it can be necessary to cleanup old workspaces.  For example, when a computername is re-used, and the same local directory is used by the new user to map a TFS folder.

You need the tool tfs.exe, which is installed togetcher with Visual Studio.  You can start a Visual Studio Command Prompt. I tested the procedure below on Visual Studio 2008 and Visual Studio 2010.

In the commands below, replace serveraddress with your TFS http or https address, e.g. https://tfs.mycompany.com:8443.  You can find it in Visual Studio: menu "Team", menu-item "Connect to Team Foundation Server...", button "Servers..."

The existing workspaces for some "computername" can be queried with this TFS command:
tf.exe workspaces /computer:computername /owner:* /format:detailed /server:serveraddress
You get a list of all workspaces, with the existing mappings. It is the workspace name (behind "Workspace:") and the owner that you need in order to delete the workspace.

Now run this TFS command to remove the workspace "workspacename" for owner "owner":
tf.exe workspace /delete workspacename;owner /server:
serveraddress

The following example displays a list of all workspaces for the current user on the current computer.
c:\projects>tf workspaces
c:\projects>tf workspaces /owner:* /computer:* /server:https://***.visualstudio.com/defaultcollection.


ref : http://msdn.microsoft.com/en-us/library/54dkh0y3(v=vs.80).aspx,
http://mycomputeradventures.blogspot.in/2012/01/removing-tfs-workspaces-from-old-users.html

My Computer Adventures: Removing TFS workspaces from old users or old comp...

My Computer Adventures: Removing TFS workspaces from old users or old comp...: When working with Microsoft Team Foundation Server, sometimes it can be necessary to cleanup old workspaces.  For example, when a computerna...

The cache file C:\Users\Admin\AppData\Local\Microsoft\Team Foundation\4.0\Cache\VersionControl.config is not valid and cannot be loaded.

If you are working with TFS and get the above error, the possibility is the VersionControl.config file is corrupted and because of which you are not able to connect to TFS Server from Visual Studio.

 To get rid of the problem I had to just delete the VersionControl.config file and tried connecting to TFS from Visual Studio, it creates a new config file and everything works fine.

Monday, July 1, 2013

Cannot create/shadow copy 'XXX' when that file already exists

By default shadow copy is enabled on every appdomain created by ASP.NET. Assemblies loaded will be copied to a shadow copy cache directory, and will be used from there. So that the original file is not locked and can be modified. An error you may encounter when running ASP.Net apps with the debugger is "Cannot create/shadow copy 'XXX' when that file already exists"

Quick Fix
You have to tell ASP.NET not to shadow copy the project assemblies to the ASP.NET temporary folders file by updating your web.config with the following entry:


<configuration>
   <system.web>
      <hostingEnvironment shadowCopyBinAssemblies="false" />
   </system.web>
</configuration>

Then restart your application.