web stats analysis

C# Windows Application Archive

String was not recognized as a valid DateTime.

String was not recognized as a valid DateTime in asp.net.

String was not recognized as a valid DateTime in c#.

Using DateTime.ParseExact.

string strDate ="10/12/2012";

DateTime date = DateTime.ParseExact(strDate, "dd/MM/yyyy", null);

Cannot access a disposed object?

Following Solution:

The problem is when you close form that it can not be used anymore you have to reopened.The code you posted tries to stop closing and only hides your window.If you want to doing this then you must set cancel-property true.

Private void Max_FormClosing(object sender, FormClosingEventArgs e)  

{

this.Hide();

this.Parent = null;

Cancel=true;

}

How to replace spaces with underscores in asp.net?

How can I replace a space in a string with an underscore in C#?

Type following code in code behind.


protected void Page_Load(object sender, EventArgs e)

{

string text= "Good Morning";

Response.Write(Replace(text));

}

static string Replace(string t)

{

return System.Text.RegularExpressions..Regex.Replace(t, @"\s+", "_");

}

How to change the background color for an MDI parent form in Visual C#?

Follow below Steps:

Step:1-Create a new Visual C# Windows application.By default Form1 is created.
Step:2-Click the form -> on the View menu -> select Properties Window to view the properties for the form.
Step:3-Set BackColor property to the color that you want.
Step:4-Set the IsMDIContainer property to True.
Step:5-Set the WindowState property to Maximized.
Step:6-Then Double-click the form to view its code window.
Step:7-Copy the below code and paste into form’s load event.

MdiClient ctlMDI;

// Loop through all of the form's controls looking
// for the control of type MdiClient.
foreach (Control ctl in this.Controls)
{
   try
   {
      // Attempt to cast the control to type MdiClient.
      ctlMDI = (MdiClient) ctl;

      // Set the BackColor of the MdiClient control.
      ctlMDI.BackColor = this.BackColor;
   }
   catch (InvalidCastException exc)
   {
      // Catch and ignore the error if casting failed.
   }
}

// Display a child form to show this is still an MDI application.
Form2 frm = new Form2();
frm.MdiParent = this;
frm.Show();
Step:8-On the Project menu -> Add Windows Form.
Step:9-Accept the default name Form2.cs, and then click Open.
Step:10-Finally press F5 to run the application.
Note:-That the background color of the form changes to the color that the Application
Background color is set to in Control Panel.

Error: The name ‘CommandType’ does not exist in the current context.

Error: The name ‘SqlDbType’ does not exist in the current context.

Add following namespace

using System.Data;

How to change date format in c# asp .net?

Below asp.net date format example:


string format = "dd/MM/yyyy";

string date = Convert.ToDateTime("2013-09-05 09:34:43").ToString(format);

Response.Write(date.ToString());

How to read data from excel file using c#?

using OleDB and use the Excel file like a datatable in a database you can read data from excel file.

Like see in below example:


string con = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=path;
Extended Properties='Excel8.0;HDR=Yes;'"
using(OleDbConnection cn= new OleDbConnection(con))
{
cn.Open();
OleDbCommand olcmd = new OleDbCommand("select * from [Sheet1$]", cn)
using(OleDbDataReader dr = olcmd.ExecuteReader())
{
while(dr.Read())
{
var row1Col0 = dr[0];
Console.WriteLine(row1Col0);
}
}
}

Above example use the Microsoft.Jet.OleDb.4.0 provider to open and read the Excel file.

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

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

Just add the below namespace:

using System.Windows.Forms;

How to get dynamic value in dropdownlist in asp.net?

How to get value of menu type in C# code?

I try and got solution is below:

Just add the below code into your particular page.


public static void dropdownbind1(string strtbl, string field, DropDownList dl, string dttext, string dtvale)
{
dl.Items.Clear();
str = "select distinct " + field + " from " + strtbl + ""
cmd = new MySqlCommand(str, Classmysql.con);
dtp = new MySqlDataAdapter(cmd);
ds = new DataSet();
dtp.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
dl.DataSource = ds;
dl.DataTextField = dttext;
dl.DataValueField = dtvale;
dl.DataBind();
dl.Items.Insert(0, "SELECT");
}
else
{
dl.Items.Insert(0, "no details");

}
here is the example.it is general method.

}

Your problem has been solve.

How to open PDF files in web brower using asp.net?

Asp.net open PDF file in web browser using C#.

I have a simple solution is like below:

First create one new website and add one of your existing pdf file to your website after that open Default.aspx page and write the following code.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Open PDF File in Web Browser in asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnOpen" Text="1st Show PDF In Browser" Font-Bold="true" runat="server" onclick="btnOpen_Click" />
<asp:Button ID="btnpdf" Text="2nd Show PDF In Browser" Font-Bold="true" runat="server" onclick="btnpdf_Click" />
</div>
</form>
</body>
</html>

Open Default.aspx.cs file and add following namespace:

using System;

using System.Net;

After added namespace write the following code:


protected void Page_Load(object sender, EventArgs e)
{
}
// First Way to show PDF in browser

protected void btnOpen_Click(object sender, EventArgs e)
{
Response.Redirect("SiteAnalytics.pdf");
}

protected void btnpdf_Click(object sender, EventArgs e)
{
string path = Server.MapPath("SiteAnalytics.pdf");
WebClient client = new WebClient();
Byte[] buffer = client.DownloadData(path);

if (buffer != null)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", buffer.Length.ToString());
Response.BinaryWrite(buffer);
}
}

Hope it help you better: