Monday, January 21, 2019

MySQL Connection using mysqli

<?php
$servername = "localhost";
$username = "username";
$password = "password";

// Create connection$conn = new mysqli($servername, $username, $password);

// Check connectionif ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
echo "Connected successfully";
?>


Friday, July 15, 2011

File Upload Control C#

protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
try
{
// SaveAs method of PostedFile property used
// to save the file at specified rooted path
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/App_Data") + System.IO.Path.DirectorySeparatorChar + FileUpload1.PostedFile.FileName);

// success message
Label1.Text = "File " + FileUpload1.PostedFile.FileName + " uploaded successfully.";
}
catch (Exception ex)
{
// error message
Label1.Text = "Some problem occurred while uploading the file. Please try after some time.";
}
}
else
{
// warning message
Label1.Text = "Please choose a file to upload.";
}
}
---------------------------------------------

ASP.Net File Upload Example using C# code

Updated on 20 Aug 2010, Published on 30 Oct 2009

In the previous tutorial: ASP.Net FileUpload Control PostedFile property we learnt about its accessible member properties and method. As it provides the object of HttpPostedFile class it points the memory stream of the uploaded file stored in the cache area of server memory. You can access different attributes of the uploaded file using the accessible properties of PostedFile property of FileUpload control. In this tutorial we will use the simplest C# code to learn the very basic steps for uploading file selected from the client’s computer system to the web server location specified in the code.

Apart from FileUpload server control for uploading a file you need very few things to write up a simplest C# code. First you need to verify the state of the FileUpload control whether it contains a file or not otherwise the properties accessed using FileUpload control object may throw as error or exception of "System.NullReferenceException: Object reference not set to an instance of an object.". You can use the HasFile property to verify that the fileupload control contains a file that is to be uploaded.

Next you need a method to specify the location where to save the uploaded file. The ASP.Net FileUpload control caches the file contents into the server memory before executing the server code. That is why you just need to call the SaveAs method of PostedFile object reference type property of fileupload control specified with location where you want to save the uploaded file.

Sample Code for ASP.Net File Uploading using C#

HTML Code:










In the HTML code we have used ASP.Net button control to provide the server side code mechanism that will allow the user to upload the file by clicking the button. You can specify your code in the associated click event handler of button control to upload the file to the server.

C# Code:

protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
try
{
// SaveAs method of PostedFile property used
// to save the file at specified rooted path
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/App_Data") + System.IO.Path.DirectorySeparatorChar + FileUpload1.PostedFile.FileName);

// success message
Label1.Text = "File " + FileUpload1.PostedFile.FileName + " uploaded successfully.";
}
catch (Exception ex)
{
// error message
Label1.Text = "Some problem occurred while uploading the file. Please try after some time.";
}
}
else
{
// warning message
Label1.Text = "Please choose a file to upload.";
}
}

By default SaveAs method of PostedFile property accepts the full rooted path to save the file at a specified location. You can use the Server.MapPath function to generate the full rooted path mapped according to the current web application as we have done in the above C# code. You can enable or disable the rooted path configuration of SaveAs method by specifying it in the httpRuntime setting of web.config file using requireRootedSaveAsPath attribute. It accepts the Boolean type value to enable/disable the feature. If you will specify its value as “false” then SaveAs method automatically maps the path to the "C:\Windows\System32" directory of the web server to save the uploaded file. So, it is recommended to use the default value for the requireRootedSaveAsPath configuration setting of SaveAs method.

You can specify the value for requireRootedSaveAsPath property inside httpRuntime element of system.web section of web.config file as follows:

----------

protected void UploadButton_Click(object sender, EventArgs e) {     if(FileUploadControl.HasFile)     {         try         {             if(FileUploadControl.PostedFile.ContentType == "image/jpeg")             {                 if(FileUploadControl.PostedFile.ContentLength < 102400)                 {                     string filename = Path.GetFileName(FileUploadControl.FileName);                     FileUploadControl.SaveAs(Server.MapPath("~/") + filename);                     StatusLabel.Text = "Upload status: File uploaded!";                 }                 else                     StatusLabel.Text = "Upload status: The file has to be less than 100 kb!";             }             else                 StatusLabel.Text = "Upload status: Only JPEG files are accepted!";         }         catch(Exception ex)         {             StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;         }     } }




protected void UploadButton_Click(object sender, EventArgs e)
{
if(FileUploadControl.HasFile)
{
try
{
if(FileUploadControl.PostedFile.ContentType == "image/jpeg")
{
if(FileUploadControl.PostedFile.ContentLength < 102400)
{
string filename = Path.GetFileName(FileUploadControl.FileName);
FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
StatusLabel.Text = "Upload status: File uploaded!";
}
else
StatusLabel.Text = "Upload status: The file has to be less than 100 kb!";
}
else
StatusLabel.Text = "Upload status: Only JPEG files are accepted!";
}
catch(Exception ex)
{
StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
}
}
}

Thursday, May 26, 2011

ASP.NET Web Sites for Mobile Devices 4.0 , visual studio 2010

Developing ASP.NET pages for mobile device browsers does not differ substantially from developing pages for desktop browsers. To help you create applications for mobile devices, ASP.NET provides a System.Web.Mobile namespace devoted specifically to mobile Web development.

You can create a Web page from the MobilePage base class and add controls from the System.Web.Mobile namespace. This namespace defines a suite of Web server controls and adapters that are especially useful when creating applications that need to be available to many different mobile devices, such as cell phones.

ASP.NET also provides a control-adaptive architecture that allows custom device adapters to be created for ASP.NET Web server controls. The adapters can create custom rendering for a control based on the requesting browser. With the adaptive architecture, you can create custom adapters for ASP.NET Web server controls to render output specific to the devices that access your application on desktop browsers.

Whether developing for desktop browsers or mobile devices, development follows the standard .NET event-driven model in which your application responds to user requests, button clicks, and so on.

http://msdn.microsoft.com/en-us/library/ms178619.aspx#MobileApplicationArchitecture


Sunday, January 16, 2011

How to uninstall deep freeze - defreeze.exe

To uninstall the software Deep Freeze must first be disabled and then uninstalled.
To disable Deep Freeze:

  1. Hold down the shift key and double-click on the Deep Freeze icon. Alternatively, you can press Crtl-Alt-Shift-F6. You should now see a password dialog.
  2. Enter your password and click OK. If you have not yet entered a password you should be able to click OK without entering anything. You should now see a dialog with boot options.
  3. Select "Boot thawed" and click OK. This will disable Deep Freeze on the next reboot.
  4. Reboot your machine. After the machine reboots you are ready to uninstall Deep Freeze.
To uninstall:
  1. Locate the installation file you used to install Deep Freeze to this machine. By default the name of this file is called "DF5Std.exe" for versions 5.X and "DF6Std.exe" for versions 6.X.
  2. Run the installation file (DF5Std.exe or DF6Std.exe).
  3. Select the option to "Uninstall"
  4. The software should uninstall and reboot the machine. When the machine reboots, Deep Freeze should be uninstalled.

Wednesday, June 18, 2008

SqlDataadapter

//*** don't run more than once ***
String selectCommand = "SELECT EmployeeID FROM Employees";
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["Sql_ConnectString"]);
SqlDataAdapter da = new SqlDataAdapter(selectCommand, conn);

DataTable table = new DataTable("Employees");
da.FillSchema(table, SchemaType.Source);
da.Fill(table);

conn.Open();
foreach(DataRow row in table.Rows)
{
Int32 employeeId = (Int32)row["EmployeeID"];

String sqlRead = "SELECT Photo FROM Employees WHERE EmployeeID=" + employeeId;
SqlCommand cmdRead = new SqlCommand(sqlRead, conn);

MemoryStream ms = new MemoryStream();
Byte[] image = (Byte[])cmdRead.ExecuteScalar();
ms.Write(image, MSACCESSIMAGEOFFSET, image.Length - MSACCESSIMAGEOFFSET);

String sqlWrite = "UPDATE Employees SET Photo = @Photo WHERE EmployeeID=" + employeeId;
SqlCommand cmdWrite = new SqlCommand(sqlWrite, conn);

//Create parameter for insert command and add to SqlCommand object.
SqlParameter prm = new SqlParameter("@Photo", SqlDbType.VarBinary, ms.ToArray().Length, ParameterDirection.Input, false,
0, 0, null, DataRowVersion.Current, ms.ToArray());
cmdWrite.Parameters.Add(prm);

//Execute query.
cmdWrite.ExecuteNonQuery();
}
conn.Close();
}
}

Query String

Response.Redirect("Welcomepage.aspx?Name=Zam&place=kerala");


Response.Write("My details " +"Name :" +Request.QueryString["Name"]+" "+"Place :"+Request.QueryString["place"]);
Response.Write("Hello" + Request.QueryString["Name"]);

session
------
Session["Name"] = "World hello ";

Response.Redirect("WebForm3.aspx");
2nd page
Response.Write("Name::::" + Session["Name"]);

Tuesday, June 10, 2008

System.Diagnostics.Process.Start

StreamWriter sw;
private void button1_Click(object sender, EventArgs e)
{
sw = File.CreateText("C:\\Zm1.html");
sw.WriteLine("HTML>HEAD>TITLE>/TITLE>/HEAD>");
sw.WriteLine("BODY>H1>HELLO/H1>/BODY>");
sw.WriteLine("/HTML>");
sw.Close();
}

private void button2_Click(object sender, EventArgs e)
{

System.Diagnostics.Process.Start("iexplore", "C:\\Zm1.html");
}
}