private void loadImageGrid()
 {
     ProcessImageUrl _imageInfo = new ProcessImageUrl();
     try
     {
         int _comID = int.Parse(Session["trkCompany"].ToString());
         _imageInfo.GetImageInfo(_comID);
         _rgrdAdImage.DataSource = _imageInfo.Ds;
         //_rgrdAdImage.DataBind();
     }
     catch (Exception ex)
     {
         ex.Message.ToString();
     }
     finally
     {
         _rgrdAdImage = null;
     }
 }
    protected void _rgrdAdImage_DeleteCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        GridEditableItem editedItem = e.Item as GridEditableItem;
        string _imageID = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["ID"].ToString();
        Label name = (Label)e.Item.FindControl("_lblImageName");
        string _imageName = name.Text.ToString();

        ProcessImageUrl _imageInfo = new ProcessImageUrl();
        ImageURL _iObj = new ImageURL();
        try
        {
            _iObj.Id = int.Parse(_imageID.ToString());

            _imageInfo.IUrl = _iObj;
            _imageInfo.DeleteImageInfo();

            DeleteFile(_imageName);
            _lblMessage.Text = "Image Deleted successfully.";

        }
        catch (Exception ex)
        {
            ex.Message.ToString();
        }
        finally
        {
            _imageInfo = null;
        }
    }
    protected void _rgrdAdImage_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        GridEditableItem editedItem = e.Item as GridEditableItem;
        string ImageID = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["ID"].ToString();
        string ImageURL = (editedItem["ImageURL"].Controls[0] as TextBox).Text;
        //string _imageName = (editedItem["ImageName"].Controls[0] as TextBox).Text;
        int IsActive = 0;
        bool Status = (editedItem["IsActive"].Controls[0] as CheckBox).Checked;

        if (Status)
        {
            IsActive = 1;
        }

        ProcessImageUrl _imageInfo = new ProcessImageUrl();
        ImageURL _iObj = new ImageURL();
        try
        {
            _iObj.Id = int.Parse(ImageID.ToString());
            _iObj.ImageUrl = ImageURL;
            _iObj.ComID = int.Parse(Session["trkCompany"].ToString());
            _iObj.IsActive = IsActive;

            _imageInfo.IUrl = _iObj;
            _imageInfo.UpdateImageInfo();
            _rgrdAdImage.Rebind();
            _lblMessage.Text = "Image Updated successfully.";
        }
        catch (Exception ex)
        {
            ex.Message.ToString();
        }
        finally
        {
            _imageInfo = null;
        }
    }
    protected void _btnUpload_Click(object sender, EventArgs e)
    {
        string sSavePath = "";
        string sFilename = "";
        try
        {
        ProcessImageUrl pIu = new ProcessImageUrl();
        ImageURL imgU = new ImageURL();

        int intThumbWidth = 200;
        int intThumbHeight = 50;

        // Set constant values

        sSavePath = "..\\AdvertisingImages\\";

            // If file field isn’t empty

            if (FileInput.PostedFile != null)
            {
                // Check file size (mustn’t be 0)

                HttpPostedFile myFile = FileInput.PostedFile;

                int nFileLen = myFile.ContentLength;
                if (nFileLen == 0)
                {
                    _lblMessage.Text = "No file was uploaded.";
                    return;
                }

                // Check file extension (must be JPG)

                if (System.IO.Path.GetExtension(myFile.FileName).ToLower() != ".jpg")
                {
                    _lblMessage.Text = "The file must have an extension of JPG";
                    return;
                }

                // Make sure a duplicate file doesn’t exist.

                sFilename = Path.GetFileName(myFile.FileName);

                if ((File.Exists(Server.MapPath(sSavePath + sFilename))))
                {
                    _lblMessage.Text = "File with same name already exist";
                    return;
                }

                //System.Drawing.Image FullsizeImage = System.Drawing.Image.FromFile();

                //myFile.SaveAs(sSavepath+Path.GetFileName(myFile.FileName));AdvertisingImages
                //string fileName = "";
                //string fullName = myFile.FileName.ToString();

                //if(fullName.LastIndexOf('/') > 0 )
                //{
                //    fileName = fullName.Substring(fullName.LastIndexOf('/'),fullName.Length);
                //}
                string filerPath = Server.MapPath("AdvertisingImages");
                string filePath = filerPath.Replace("\\CompanyAdmin", "");
                 myFile.SaveAs(filePath + "\\a.jpg");
                 string fullpath = filePath + "\\" + Path.GetFileName(myFile.FileName);
                 ResizeImage(filePath + "\\a.jpg", fullpath, 200, 60, true);
                 File.Delete(filePath + "\\a.jpg");

                //lblGridMessage.ForeColor = System.Drawing.Color.Green;
                //lblGridMessage.Text = "Icon Created Successfully...";
                // Resizing Image has comments on 24.12.2008 due to browser bug.

                //bool flag = ResizeImage(Path.GetFullPath(myFile.FileName), Server.MapPath(sSavePath + sFilename), intThumbWidth, intThumbHeight, true);
                //if (!flag)
                //{
                //    _lblMessage.Text = "File upload fail.";
                //    return;
                //}

                // Entry to Database

                int isActive = 0;
                if (_chkIsActive.Checked)
                {
                    isActive = 1;
                }
                else
                {
                    isActive = 0;
                }
                imgU.ImageName = sFilename;
                imgU.ImageUrl = _txtURL.Text.ToString();

                int _cID = int.Parse(Session["trkCompany"].ToString());
                imgU.ComID = _cID;
                imgU.IsActive = isActive;

                pIu.IUrl = imgU;

                pIu.AddImageUrl();

                // Displaying success information

                _lblMessage.Text = "File uploaded successfully!";
                _txtURL.Text = "";
                //loadImageGrid(_cID);
                _rgrdAdImage.Rebind();

               // _rgrdAdImage.Rebind();
                // Destroy objects

            }
        }
        catch (Exception errArgument)
        {

            //_lblMessage.Text = "File upload fail. "+ errArgument.Message.ToString();
           // File.Delete(Server.MapPath(sSavePath + sFilename));
        }
    }