Friday, December 6, 2013

Sort DateTime List c#

    
    var sortedDates = dates.OrderByDescending(x => x);

or else Don't want to use, or don't know Linq then you can go for following..

    static List SortAscending(List list)
    {
    list.Sort((a, b) => a.CompareTo(b));
    return list;
    }

    static List SortDescending(List list)
    {
    list.Sort((a, b) => b.CompareTo(a));
    return list;
    }

Wednesday, December 4, 2013

Directory does not exist. Parameter name: directoryVirtualPath

I had the same problem and found out that I had some bundles that pointed to non-exisiting files using {version} and * wildcards such as
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
    "~/Scripts/jquery-{version}.js"));
I removed all of those and the error went away.

Code to Randomize data in a list

Random rand = new Random();
latestdata = latestdata.OrderBy(c => rand.Next()).ToList();

Structure data for Movie & review

<div itemtype="http://schema.org/Movie">
    <ul>
    <li>Title : <a itemprop="name" style="color: black;" title=""></a></li>
    <li>Star Cast :<a itemprop="actor" itemscope="" itemtype="http://schema.org/Person" title=""><span itemprop="name">Sundeep Kishan</span></a>
<a itemprop="actor" itemscope="" itemtype="http://schema.org/Person" title=""><span itemprop="name">Rakul Preet Singh</span></a>
    </li>
    <li>Director : <a itemprop="director" itemscope="" itemtype="http://schema.org/Person" title=""><span itemprop="name"></span></a></li>
    <li>Producer : <a itemprop="producer" itemscope="" itemtype="http://schema.org/Person" title=""><span itemprop="name"></span></a></li>
    <li>Music : </li>
    <li>Released on : Nov 29, 2013.</li>
    </ul>

    <a itemprop="author" itemscope="" itemtype="http://schema.org/Person"><span itemprop="name"></span></a>
    <a itemprop="creator" itemscope="" itemtype="http://schema.org/Person"><span itemprop="name"></span></a>
    <a itemprop="publisher"></a>
    <span itemprop="description"></span>
    <span itemprop="keywords"></span>

    <div itemprop="review" itemscope itemtype="http://schema.org/Review">
        <span itemprop="name"></span>
        <span itemprop="author"></span>
        <meta itemprop="datePublished" content="" />
        <span itemprop="description"</span>
        <span itemprop="keywords"></span>
    </div>
</div>

Wednesday, October 23, 2013

Xcode 5 - SpringBoard failed to launch application with error: -3

options 

1.) Deleting the app from simulator solved this.

2.) Quitting simulator seems to help.

3.) Restart simulator, if it wont solve your problem and then delete all content. theres a option for resetting simulator.. use that ...

Monday, September 30, 2013

Friday, August 16, 2013

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.

Friday, June 21, 2013

Problem with converting int to string in Linq to entities

With EF v4 you can use SqlFunctions.StringConvert. There is no overload for int so you need to cast to a double or a decimal. Your code ends up looking like this:
var items = from c in contacts
        select new ListItem
        {
            Value = SqlFunctions.StringConvert((double)c.ContactId),
            Text = c.Name
        };

Saturday, April 27, 2013

MVC 4 Web Api IIS7.5 HTTP web config issues


<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
        
            <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
            <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
        </handlers>
</system.webServer>
ref : http://stackoverflow.com/questions/9703090/mvc-4-web-api-iis7-5-http-404-page-not-found
I was struggling with this as well. Fortunately, Steve Michelotti documented a solution that worked for me here.
At the end of the day, I enabled all verbs (verb="*") to the ExtensionlessUrlHandler-Integrated-4.0 handler in my web config.

How to change File and Folder permissions on windows OS using Command Line (CLI)?

The following commands will help to take the ownership of the directory and files:
D:\>takeown /f D:\path\to\directory /r /d y
D:\>icacls D:\path\to\directory /grant administrators:F /t

Thursday, April 18, 2013

jquery click event not firing?


Is this markup added to the DOM asynchronously? You will need to use live in that case:
The fact that you are able to re-run your script block and have it work tells me that for some reason the elements weren't available at the time of binding or the binding was removed at some point. If the elements weren't there at bind-time, you will need to use live (or event delegation, preferably). Otherwise, you need to check your code for something else that would be removing the binding.
Using jQuery 1.7 event delegation:
$(function () {

    $('.play_navigation').on('click', 'a', function (e) {
        console.log('this is the click');
        e.preventDefault();
    });

});
You can also delegate events up to the document if you feel that you would like to bind the event before the document is ready (note that this also causes jQuery to examine every click event to determine if the element matches the appropriate selector):
$(document).on('click', '.play_navigation a', function (e) {
    console.log('this is the click');
    e.preventDefault();
});


ref : http://stackoverflow.com/questions/5540561/jquery-click-event-not-firing

Wednesday, February 20, 2013

Windows Phone toolkit 4 (How to install)

Here is how you can install the Windows Phone 8 version of the 

toolkit 



Windows Phone toolkit provides a collection of controls, extension methods and page animations to help create beautiful and consistent Windows Phone user interfaces and make common progamming tasks easier. Documentation and source are on CodePlex at http://phone.codeplex.com.
NO. 1) To install Windows Phone toolkit, run the following command in the Package Manager Console

PM> Install-Package WPtoolkit

NO. 2) via NuGet in an easy way using only Visual Studio.

Step1. Create a new Widows Phone 8 Application Project in Visual Studio:
image
Step2. If you have not used NuGet before then go to "VisualStudio Tools-> Extentions and Updates.." as demonstrated below:
image
Step3.Go to "Visual Studio Gallery" tab and type "Nuget" in the search box. Next  install "NuGet Package Manager"  as demonstrated below:
image
image image
NOTE: Once the installation has finished, you must restart Visual Studio, in order for the changes to take effect!
image
Step4. After you have installed the NuGet Package Manager just right-click the References folder in your project and from the context menu select the "Manage NuGet Packages.." option:
image
Step5-a. A new window will appear where you can search for a particular package. So just start typing "windows phone toolkit"  in the search box and you should see the "Windows Phone Toolkit " package on top. Next press install.
image
Step5-b: Alternatively you can Installing he "Windows Phone Toolkit " package using the command line:
Just go to View ->Other Windows -> Package Manager Console:
image
Next type the following code in the console:
PM> Install-Package WPtoolkit
Step6. After the installation has finished you should see the following:
image
Step7. That was all. You will notice that your project now references the Windows Phone Toolkit  assemblies and a new Toolkit.Content Model folder has been automatically added to your project. Your project is now set up and  you are ready to start using the Windows Phone Toolkit  in your application..
image
Step8. Later if you want to update to a new  version of  the Windows Phone Toolkit  , you can use the following NuGet command:
PM> Update-Package WPtoolkit
That was all about how to install Windows Phone Toolkit - October 2012 (8.0 SDK) via NuGet.

Tuesday, February 19, 2013

Windows Phone : ShareStatusTask and ShareLinkTask


In this post I am going to talk about ShareLinkTask and ShareStatusTask that come with the Windows Phone Mango update of the developer tools.
Note: ShareLinkTask and ShareStatusTask do not work on the emulator. So you will need real Mango device connected to Facebook,Windows Live, etc. in order to test them.
ShareLinkTask
Basically ShareLinkTask launches a dialog that enables the user to share a link on the social networks like for example Facebook, Windows Live, etc.
To start using it you will need to include the following namespace:
Namespace:  Microsoft.Phone.Tasks 
Assembly:  Microsoft.Phone (in Microsoft.Phone.dll)
 
All you need to do in order to this launchers in your application is:
Step1: Create an instance of  ShareLinkTask,
Step2: Set desired propertied: Title, LinkUri, Message.
Step3. Call Show():

ShareLinkTask shareLinkTask = new ShareLinkTask();
shareLinkTask.Title = "WindowsPhoneGeek";
shareLinkTask.LinkUri = new Uri("http://windowsphonegeek.com", UriKind.Absolute);
shareLinkTask.Message = "The ultimate resource for Windows Phone Development.";
shareLinkTask.Show();

ShareStatusTask
Basically  ShareStatusTask launches a dialog that enables the user to share a status message on the social networks (Facebook, Windows Live, etc.).
To start using it you will need to include the following namespace:
Namespace:  Microsoft.Phone.Tasks 
Assembly:  Microsoft.Phone (in Microsoft.Phone.dll)
All you need to do in order to this launchers in your application is:
Step1: Create an instance of  ShareStatusTask,
Step2: Set desired propertied: Status.
Step3. Call Show():

ShareStatusTask shareStatusTask = new ShareStatusTask();
shareStatusTask.Status = "Current Status: Developing WP7 apps.";
shareStatusTask.Show();

That was all about using ShareLinkTask and ShareStatusTask in a Windows Phone Mango application. You can find the full source code of the demo here: