web stats analysis

Archive for August 22nd, 2013

String was not recognized as a valid DateTime.

String was not recognized as a valid DateTime

Follow below solution:

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

Syntax:


public static DateTime ParseExact(
string str,
string format,
IFormatProvider provider
)
str

=> contain date and time to convert.
format => It is specify that define the required format of str.

provider

=> It is a object that supplies culture-specific format information about str.

Exceptions

Exception Condition
ArgumentNullException str or format is null.
FormatException str or format is an empty string.
-or-
str does not contain a date and time that corresponds to the pattern specified in format.
-or-
The hour component and the AM/PM designator in str do not agree.

Demo of ParseExact method


using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      string String, format;
      DateTime result;
      CultureInfo provider = CultureInfo.InvariantCulture;

      // Parse date-only value with invariant culture.
      String = "06/15/2008";
      format = "d";
      try {
         result = DateTime.ParseExact(dateString, format, provider);
         Console.WriteLine("{0} converts to {1}.", dateString, result.ToString());
      }
      catch (FormatException) {
         Console.WriteLine("{0} is not in the correct format.", String);
      } 

      // Parse date-only value without leading zero in month using "d" format.
      // Should throw a FormatException because standard short date pattern of
      // invariant culture requires two-digit month.

      String = "6/15/2008";
      try {
         result = DateTime.ParseExact(dateString, format, provider);
         Console.WriteLine("{0} converts to {1}.", String, result.ToString());
      }
      catch (FormatException) {
         Console.WriteLine("{0} is not in the correct format.", String);
      }

      // Parse date and time with custom specifier.

      String = "Sun 15 Jun 2008 8:30 AM -06:00";
      format = "ddd dd MMM yyyy h:mm tt zzz";
      try {
         result = DateTime.ParseExact(dateString, format, provider);
         Console.WriteLine("{0} converts to {1}.", String, result.ToString());
      }
      catch (FormatException) {
         Console.WriteLine("{0} is not in the correct format.", String);
      }

      // Parse date and time with offset but without offset's minutes.
      // Should throw a FormatException because "zzz" specifier requires leading
      // zero in hours.

      String = "Sun 15 Jun 2008 8:30 AM -06";
      try {
         result = DateTime.ParseExact(String, format, provider);
         Console.WriteLine("{0} converts to {1}.", String, result.ToString());
      }
      catch (FormatException) {
         Console.WriteLine("{0} is not in the correct format.", String);
      } 

      String = "15/06/2008 08:30";
      format = "g";
      provider = new CultureInfo("fr-FR");
      try {
         result = DateTime.ParseExact(String, format, provider);
         Console.WriteLine("{0} converts to {1}.", String, result.ToString());
      }
      catch (FormatException) {
         Console.WriteLine("{0} is not in the correct format.", String);
      }
   }
}

// The example displays the following output:
//       06/15/2008 converts to 6/15/2008 12:00:00 AM.
//       6/15/2008 is not in the correct format.
//       Sun 15 Jun 2008 8:30 AM -06:00 converts to 6/15/2008 7:30:00 AM.
//       Sun 15 Jun 2008 8:30 AM -06 is not in the correct format.
//       15/06/2008 08:30 converts to 6/15/2008 8:30:00 AM.

How to add android date time picker?

Android Date Time Picker Dialog.

Add the following namespace.

->Android additionally supports widgets such as DatePicker, TimePicker as well as dialogs just like DatePickerDialog, TimePickerDialog for helping users enter dates and times.
->The DatePicker and also DatePickerDialog are same it’s enable you to set the starting date for selection, in the form of a year, month, and day of month value.
->Both are give a callback object OnDateChangedListener or even OnDateSetListener where you are informed of a new date selected from the user.
->You are able to store that date somewhere because there is no some other way for you to get at the chosen date later on.
->To Test this Date and Time Picker widget, create an android project and place two buttons.One for set the date and another one for set the time. And display the end result in a textview.

Demo example of Date Time picker is like below:

Creating Layout for Date Time Picker Widget


main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <TextView
        android:id="@+id/timeTxt"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/time_text" />
    <Button
        android:id="@+id/dateBtn"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/set_date"
        android:onClick="chooseDate"
        />
    <Button
        android:id="@+id/timeBtn"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/set_time"
        android:onClick="chooseTime"
        />
</LinearLayout>

Java code to configure the Date Time Picker Widget:


AndroidDateTimePickerActivity.java

package com.vimaltuts.android.androiddatetimepicker;
import java.util.Calendar;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import java.text.DateFormat;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.TimePicker;
public class AndroidDateTimePickerActivity extends Activity {
private Button timeBtn;
private Button dateBtn;
DateFormat formatDateTime=DateFormat.getDateTimeInstance();
Calendar dateTime=Calendar.getInstance();
private TextView timeLabel;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
timeLabel=(TextView)findViewById(R.id.timeTxt);
updateLabel();
}
public void chooseDate(){
new DatePickerDialog(AndroidDateTimePickerActivity.this, d, dateTime.get(Calendar.YEAR),dateTime.get(Calendar.MONTH), dateTime.get(Calendar.DAY_OF_MONTH)).show();
}
public void chooseTime(){
new TimePickerDialog(AndroidDateTimePickerActivity.this, t, dateTime.get(Calendar.HOUR_OF_DAY), dateTime.get(Calendar.MINUTE), true).show();
}
DatePickerDialog.OnDateSetListener d=new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,int dayOfMonth) {
dateTime.set(Calendar.YEAR,year);
dateTime.set(Calendar.MONTH, monthOfYear);
dateTime.set(Calendar.DAY_OF_MONTH, dayOfMonth);
updateLabel();
}
};
TimePickerDialog.OnTimeSetListener t=new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
dateTime.set(Calendar.HOUR_OF_DAY, hourOfDay);
dateTime.set(Calendar.MINUTE,minute);
updateLabel();
}
};
private void updateLabel() {
timeLabel.setText(formatDateTime.format(dateTime.getTime()));
}
}
->In the button property we allocated a related method to each button that should be called when the user clicks it.
->For the DatePickerDialog, we give it a OnDateSetListener callback that updates the Calendar with the new date.
->For the TimePickerDialog, it gets a OnTimeSetListener callback to update the time part of the Calendar.

For more detail Click here..

The type or namespace name ‘NameValueCollection’ could not be found(are you missing a using directive or an assembly reference?)

Solution of The type or namespace name ‘NameValueCollection’ could not be found(are you missing a using directive or an assembly reference?)

Add the following namespace.

using System.Collections.Specialized;

The type or namespace name ‘StringBuilder’ could not be found (are you missing a using directive or an assembly reference?)

Solution of The type or namespace name ‘StringBuilder’ could not be found (are you
missing a using directive or an assembly reference?)

Add the following namespace.

using System.Text;

The type or namespace name ‘MD5′ could not be found (are you missing a using directive or an assembly reference?).

Solution of The type or namespace name ‘MD5′ could not be found (are you missing a using directive or an assembly reference?)

Add the following namespace.

using System.Security.Cryptography;

How to add ASP.NET Web Pages to a Web Site?

 

Add ASP.NET Web Pages to a Web Site

Add an existing ASP.NET Web page to a Web site project

Changing the Name of ASP.NET Web Pages

Follow below solution:

If you want to add new and existing webpages to a website so you can.Some information about creating an asp.net website.

To add new asp.net webpage to a website:

Step:1-See in right side solution explorer.

Step:2-Right click on project name -> Add new item.

Step:3-In the Add New Item dialog box, under Visual Studio installed templates, click Web Form.

Step:4-Look like this below:Click below image

Step:5-See in language list and select programming language what you want.

Step:6-Give your webpage name.

Step:7-If you want the code for the page to be in a separate file,be sure that the Place code in separate file check box is selected.

Step:8-Click Add button.

Step:9-The new ASP.NET Web page is created and displayed in the Visual Web Developer.

Note:-You can create pages with different programming languages in the same Web site.

To add an existing asp.net web page to a web site project

Step:1-See in right side solution explorer.

Step:2-Right click on project name -> Add Existing Item.

Step:3-Then select your webpage and click Add.

Step:4-The ASP.NET Web page is added to the Web site project.

Note:-When you add an existing file to a Web site, the file is copied to your project not
added by reference.if you change the file in your project, the original file is left unchanged.

Changing the name of asp.net web Pages.

After creating a new ASP.NET Web page or adding an existing page to a Web site project,
you might want to change the name of the page file. You can easily rename pages in Solution Explorer.
Step:1-In Solution Explorer, right-click the file that you want to change and then click Rename.

Step:2-Type the new file name what you want and then press ENTER.