Expertize Essentials Innovation through knowledge

22Jul/093

ASP.NET Control Gallery

Microsoft Official Site has a very good collection of ASP.NET controls. The control can be used on a variety of website of different areas.

These controls contains:

Mobile Controls:

These controls are really very useful if you are a asp.net developer. By using these controls and tips will resolve your most of problems in minutes.

So Enjoy :)

21Jul/097

Use Your Left Ear while listening to Mobile Phones

Potential new risk from mobile phones:

Please use left ear while using cell (mobile), because if you use the right one it will affect brain directly. This is a true fact from Apollo medical team. Please forward this information to all your well wishers

Mobile Phone Risks

"Is real or hoax..."

Well, the caption is definitely a hoax. I have no idea what the Apollo medical team is. (When I google the term I just pull up references to this email.) And the suggestion that it would somehow be safer to use your left ear rather than your right is absurd.

However, the graphic and the information in it are not a hoax. The illustration was created by the Graphic News agency back in 2002. (Click 'Graphic Search' on their site, then do a keyword search for the term 'blood-brain barrier', and you'll pull up the graphic.) The information it describes comes from a study published in the May 2002 issue of the scientific journal Differentiation. Researcher Darius Leszcynski did find that when human endothelial cells were exposed to the maximum level of radiation allowed under international safety standards for mobile phones, a stress response could be observed in the cells. But he also noted that most mobile phones emit much less radiation than the levels used in the experiment. So there's probably no imminent danger of damaging your blood-brain barrier by using a mobile phone.

Original Source: http://www.museumofhoaxes.com/hoax/weblog/comments/3888/

Tagged as: 7 Comments
16Jul/099

Developing Hello World Application in Blackberry

Those have experience in .net and are new to mobile application development, will find this article useful for developing your first application on blackberry mobile.

For developing blackberry mobile application you need to have pre-requisite installed on your computer (see my other article for installing pre-requites for blackberry development).

For short, you should have installed :

  • Blackberry plug-in for Visual Studio 2005/2008

If you have this plug-in in your visual studio then move ahead.

Step 1.

  • Open Visual Studio
  • On File Menu-> New Project
  • Select Blackberry from left panel -> Blackberry MDS Runtime Application
  • Name your application to BlackberryHelloWold

Note: Please remember when you'll click OK "MDS development server" will start in system tray.

You'll see blackberry mobile screen available on your visual studio along with blackberry controls onto the left side.

Step 2.

  • Drag a TextBox from the toolbox to the blackberry form
  • Click right button of mouse on TextBox and select Properties
  • In Properties window (right side), change name to txtName
  • Now drag a button and drop it to the form just below the txtName (TextBox)
  • Change its name to btnOK
  • Change its Text to OK from Property window
  • Double click on the button (btnOK)
  • Form1_btnOK_Click() will be appeared in .js file (this creates .js file not cs file) and write the following in for display text in dialog box.
function Form1_btnOK_Click()
{
    Dialog.display(Form1.txtName.value);
}
  • Now Run your application (just click play symbol available in your visual studio)

This will start simulator (Just Looks like that you are running your application in mobile). Wait for some time your application will be loaded automatically.

Note: please check with Symentic Client Firewall this should not block your ports, otherwise your application will stuck and will not be run.

16Jul/094

Installing BlackBerry Plug-in for Visual Studio 2005/2008

BlackberryIf your are new to mobile application development and having experience in .NET using Visual Studio, then this article will help you a lot for developing blackberry mobile application. What you only have to do is to download and install Blackberry Plug-ins for Visual Studio 2005/2008 and install it on your system. After installing this will give you a separate environment/template for blackberry mobile application development.

For installing BlackBerry plug-in you need to be very sure for you system configuration as follows:

System Requirements

  • Microsoft® Visual Studio® 2005 or 2008 Standard or Professional
  • 1 GHz processor
  • 1 GB of RAM
  • Windows Vista™ (32-bit), Windows® XP Service Pack 2 (32-bit), or Windows Server® 2003 Service Pack 1 (32-bit)

The BlackBerry® platform supports several different ways of developing applications. Each methodology has unique strengths, but all of them will help you leverage the BlackBerry solution’s easy connectivity and robust security.

  • BlackBerry Browser Development
  • Rapid Application Development (RAD)
  • Java Application Development

I am going to discuss here for Rapid Application Development. Rapid application development provides you drag and drop tooling facility using Visual Studio plug-ins those are available on Blackberry website. RAD also lets you create customized user interfaces and access more advanced features. You can download tools Blackberry Visual Studio Plug-in.

Download Plug-in which is suitable for you. After downloading run downloaded file. Blackberry application development is ready for your visual studio.

Please find my other article for creating hello world application in blackberry.

Enjoy :)

15Jul/092

Saving Image in Database (Sql Server) using .NET

I shared and done few efforts to save image in database.

Following the the function to save image to the databse.
Database Table will look like this:

create table userphoto(
photoid int,
photo image
);

The following code will be written in ASPX page.
<asp:FileUpload ID="UploadPhoto" runat="server" CssClass="fileupload" />
<asp:Button ID="btnUpload" runat="server" CssClass="buttonOrangeLight" OnClick="btnUpload_Click" Text="Upload" />


The following method is the code for uploading an image which will be invoked on btnUpload click event.

protected void btnUpload_Click(object sender, EventArgs e)
{
  //Get the extension of your file to be uploaded
  string _fileExtension = UploadPhoto.PostedFile.FileName.Substring( UploadPhoto.PostedFile.FileName.LastIndexOf('.'));
  if (_fileExtension != ".jpg" && _fileExtension != ".gif" && _fileExtension != ".bmp" && _fileExtension !=   ".png")
  {
    ltScript.Text = "Please upload images(jpeg/gif/bmp/png) files";
    return;
  }

  int _filesize = UploadPhoto.FileBytes.Length;
  // Checking file length
  if(_filesize>200000)
  {
    ltScript.Text="Size exeeds the limit of 200 KB, please upload a file with size of maximum 200 KB";
    return;
  }

  FileUpload userImage = (FileUpload)UploadPhoto;
  Byte[] imgByte = null;
  if (userImage.HasFile && userImage.PostedFile != null)
  {
    //To create a PostedFile
    HttpPostedFile File = UploadPhoto.PostedFile;

    //Create byte Array with file len
    imgByte = new Byte[File.ContentLength];

    //force the control to load data in array
    File.InputStream.Read(imgByte, 0, File.ContentLength);
    AddUserPhoto(ID, imgByte); // calling database method
  }
  ltScript.Text = "File has been uploaded...";
}

// Database Method in C#
internal bool AddUserPhoto(string ID, Byte[] Photo)
{
  string conn = "server=yourservername; database=yourdatabasename; uid=userid; pwd=yourpassword;";
  SqlConnection _sqlConnection= new SqlConnection(conn);

  bool _isInserted = false;
  _sqlCommand = new SqlCommand();
  _sqlCommand.Connection = _sqlConnection;
  _sqlCommand.CommandText = "insert into phototable values(@ID, @Photo)";
  _sqlCommand.CommandType = CommandType.StoredProcedure;
  _sqlCommand.Parameters.Add(new SqlParameter("@ID", ID));
  _sqlCommand.Parameters.Add(new SqlParameter("@Photo", Photo ));
  try
  {
    if(_sqlCommand.Connection.State != ConnectionState.Open)
    _sqlCommand.Connection.Open();

    int _result = _sqlCommand.ExecuteNonQuery();
    if (_result > 0)
    {
      _isInserted = true;
    }
  }
  catch (SqlException ex) {
  // Your Error code goes here for exception
  }
  finally
  {
    _sqlCommand.Connection.Close();
    _sqlCommand = null;
  }
  return _isInserted;
}
15Jul/094

Showing Image from Database in ASP.NET

Add the following lines in ASP.NET file

<asp:image id="imgUserPhoto" imageurl="image.ashx?id=xvd21w54" runat="server"/>
or
<img src="http://www.blogger.com/image.ashx?id=xvd21w54" />

Create an image.ashx file and add the following code in it.

<%@ WebHandler Language="C#" %>
using System;
using System.Configuration;
using System.Web;
using System.IO;
using System.Data;
using System.Data.SqlClient;

public class image : IHttpHandler
{
  public void ProcessRequest(HttpContext context)
  {
    string id;
    if (context.Request.QueryString["id"] != null)
    {
      id = Convert.ToString(context.Request.QueryString["pid"]);
    }
    else
      throw new ArgumentException("No parameter specified");

    context.Response.ContentType = "image/jpeg";
    Stream Photo = GetPhoto(id, photonumber);
    if (Photo != null)
    {
      byte[] buffer = new byte[4096];
      int byteSeq = Photo.Read(buffer, 0, 4096);

      while (byteSeq > 0)
      {
        context.Response.OutputStream.Write(buffer, 0, byteSeq);
        byteSeq = Photo.Read(buffer, 0, 4096);
      }
    }
    else
    {
      //Loading default Image
      Byte[] imgByte = File.ReadAllBytes(context.Server.MapPath("upload_photo.JPG"));

      Photo = new MemoryStream(imgByte);
      byte[] buffer = new byte[4096];
      int byteSeq = Photo.Read(buffer, 0, 4096);

      while (byteSeq > 0)
      {
        context.Response.OutputStream.Write(buffer, 0, byteSeq);
        byteSeq = Photo.Read(buffer, 0, 4096);
      }

    }
    //context.Response.BinaryWrite(buffer);
  }
  public Stream GetPhoto(string Id, string PhotoNumber)
  {
    string conn = "server=yourservername; database=yourdatabasename; uid=userid; pwd=yourpassword;";
    SqlConnection connection = new SqlConnection(conn);

    string sqlQuery = "SELECT Photo FROM userphoto WHERE id=@id";

    SqlCommand cmd = new SqlCommand(sqlQuery, connection);
    cmd.CommandType = CommandType.Text;
    cmd.Parameters.AddWithValue("@id", Id);
    connection.Open();
    try
    {
      object img = cmd.ExecuteScalar();
      return new MemoryStream((byte[])img);
    }
    catch
    {
      return null;
    }
    finally
    {
      connection.Close();
    }
  }
  public bool IsReusable
  {
    get
    {
      return false;
    }
  }
}
15Jul/091

Creating Runtime Image Thumbnail (Asp.NET)

Upload an image and create thumbnail at runtime in ASP.NET


  protected void btnUpload_Click(object sender, EventArgs e)
  {
    //string _fileExtension = VirtualPathUtility.GetExtension(UploadPhoto.PostedFile.FileName);
    string _fileExtension = UploadPhoto.PostedFile.FileName.Substring (UploadPhoto.PostedFile.FileName.LastIndexOf('.'));
    if (_fileExtension != ".jpg" && _fileExtension != ".gif" && _fileExtension != ".bmp" && _fileExtension != ".png")
    {
      ltScript.Text = "Please upload images(jpeg/gif/bmp/png) files";
      return;
    }

    int _filesize = UploadPhoto.FileBytes.Length;
    if (_filesize > 200000)
    {
      ltScript.Text = "Size exeeds the limit of 200 KB, please upload a file with size of maximum 200 KB";
      return;
    }
    FileUpload userImage = (FileUpload)UploadPhoto;
    Byte[] imgByte = null;
    Byte[] _thumbByte = null;
    if (userImage.HasFile && userImage.PostedFile != null)
    {
      //To create a PostedFile
      HttpPostedFile File = UploadPhoto.PostedFile;
      //Create byte Array with file len
      imgByte = new Byte[File.ContentLength];
      //force the control to load data in array
      File.InputStream.Read(imgByte, 0, File.ContentLength);
      _thumbByte = GetThumbnail();

      DatabaseAdapter _dataadapt = new DatabaseAdapter();
      _dataadapt.UpdateUserPhoto(ID, imgByte, _thumbByte);

    }
    ltScript.Text = "File has been uploaded...";

  }
  private Byte[] GetThumbnail()
  {
    //Creating Thumbnail method
    System.Drawing.Image _image = System.Drawing.Image.FromStream
    (UploadPhoto.PostedFile.InputStream);
    float imgWidth = _image.PhysicalDimension.Width;
    float imgHeight = _image.PhysicalDimension.Height;
    float imgSize = imgHeight > imgWidth ? imgHeight : imgWidth;

    //the approximately pixel size of thumbnail image is 100 x 100 based on ratio
    float imgResize = imgSize <= 100 ? (float)1.0 : 100 / imgSize;
    imgWidth *= imgResize; imgHeight *= imgResize;
    //generating the thumbnail
    System.Drawing.Image _thumbnail = _image.GetThumbnailImage((int)imgWidth, (int)imgHeight, delegate() { return false; }, (IntPtr)0);

    // Converting Image File to byte Array
    byte[] imgBytes = null;
    try
    {
      using (MemoryStream ms = new MemoryStream())
      {
        _thumbnail.Save(ms, ImageFormat.Jpeg);
        imgBytes = ms.ToArray();
      }
    }
    catch (Exception ex) { ltLabel.Text = ex.ToString(); }
    return imgBytes;
  }