Click here to Skip to main content
16,020,188 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,
i want remove PhotoUploader.cs to this my code:

C#
protected void RadButton39_Click(object sender, EventArgs e)
{

    try
    {

        HttpFileCollection uploadedFiles = Request.Files;

        PhotoUploader uploader = new PhotoUploader();



        for (int i = 0; i < uploadedFiles.Count; i++)
        {
            HttpPostedFile userPostedFile = uploadedFiles[i];

            if (userPostedFile.ContentLength > 0)
            {
                using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
                {

                    uploader.StartUploadProcess(userPostedFile, 210,  "~/Img/News/");
                    string small_pic_name = uploader.LastImageName;

                    uploader.StartUploadProcess(userPostedFile, 650, "~/Img/News/");
                    string big_pic_name = uploader.LastImageName;

                    string commandText = "INSERT INTO NewsGallery(ID,   Small_pic, Big_pic) VALUES ('" + int.Parse(GridView1.SelectedDataKey.Value.ToString()) + "','" + small_pic_name + "', '" + big_pic_name + "')";
                    SqlCommand command = new SqlCommand(commandText, connection);

                    connection.Open();
                    int rowsAffected = command.ExecuteNonQuery();
                    if (rowsAffected == 1)
                    {
                        // MessageLabel.Text = "";
                    }
                    connection.Close();

                }

            }

            GridView1.DataBind();
            GridView2.DataBind();


        }
    }
    catch { }
}


and this is PhotoUploader.cs Class:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;


/// <summary>
/// Summary description for PhotoUploader
/// </summary>
public class PhotoUploader
{





    HttpPostedFile photo;
    string _imageName;
    string _path;
    string _outputMessage;
    int _newWidth;
    string _lastImageName;
    //GET AND SET IMAGE NAME
    public string ImageName
    {
        get { return _imageName; }
        set { _imageName = value; }
    }

    public string LastImageName
    {
        get { return _lastImageName; }
        set { _lastImageName = value; }
    }

    //GET AND SET IMAGE PATH
    public string Path
    {
        get { return _path; }
        set { _path = value; }
    }

    //GET AND SET NEW WIDTH
    public int NewWidth
    {
        get { return _newWidth; }
        set { _newWidth = value; }
    }

    //GET AND SET ERROR MESSAGE
    public string OutputMessage
    {
        get { return _outputMessage; }
        set { _outputMessage = value; }
    }

    public bool StartUploadProcess(HttpPostedFile ProductPhoto, int LargestWidthPX, string MapPath)
    {
        photo = ProductPhoto;
        ImageName = photo.FileName.Replace(" ", "").Replace("%20", "");

        //--- make sure image is in acceptable type
        if (ImageName.ToLower().EndsWith(".jpg") || ImageName.ToLower().EndsWith(".jpeg"))
        {
            if ((ImageName != null))
            {
                if (UploadPhoto(LargestWidthPX, MapPath))
                {
                    OutputMessage = "Photo was successfully uploaded.";
                    return true;
                }
            }
            else
            {
                OutputMessage = "No photo supplied. Please selecte a photo.";
                return false;
            }
        }
        else
        {
            OutputMessage = "The photo is not a supported type. Photo must be .jpg, .png or .gif";
            return false;
        }
        return false;
    }

    protected bool UploadPhoto(int LargestWidthPX, string MapPath)
    {
        Path = MapPath;
        photo.SaveAs(HttpContext.Current.Server.MapPath(Path + System.DateTime.Now.Day.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Year.ToString() + System.DateTime.Now.Hour.ToString() + System.DateTime.Now.Minute.ToString() + ImageName.Replace(" ", "").Replace("%20", "")));
        NewWidth = LargestWidthPX;

        if (resizeImage())
        {


            File.Delete(HttpContext.Current.Server.MapPath(Path + System.DateTime.Now.Day.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Year.ToString() + System.DateTime.Now.Hour.ToString() + System.DateTime.Now.Minute.ToString() + photo.FileName.Replace(" ", "").Replace("%20", "")));
            return true;


        }

        return false;
    }
    protected bool resizeImage()
    {
        string originalFileName = null;
        string newFileName = null;
        Bitmap tmpImage = default(Bitmap);
        Bitmap newImage = default(Bitmap);
        Graphics g = default(Graphics);
        int newHeight = 0;
        FileStream fs = default(FileStream);
        originalFileName = HttpContext.Current.Server.MapPath(Path + System.DateTime.Now.Day.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Year.ToString() + System.DateTime.Now.Hour.ToString() + System.DateTime.Now.Minute.ToString() + ImageName.Replace(" ", "").Replace("%20", ""));
        if (File.Exists(originalFileName))
        {
            try
            {
                fs = new FileStream(originalFileName, FileMode.Open);
                tmpImage = (Bitmap)Bitmap.FromStream(fs);
                fs.Close();

                newHeight = (NewWidth * tmpImage.Height) / tmpImage.Width;
                newImage = new Bitmap(NewWidth, newHeight);
                g = Graphics.FromImage(newImage); g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; g.DrawImage(tmpImage, 0, 0, NewWidth, newHeight);
                g.Dispose();

                newFileName = NewWidth.ToString() + "_" + ImageName.Replace(" ", "").Replace("%20", "");
                newImage.Save(HttpContext.Current.Server.MapPath(Path + System.DateTime.Now.Day.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Year.ToString() + System.DateTime.Now.Hour.ToString() + System.DateTime.Now.Minute.ToString() + newFileName), System.Drawing.Imaging.ImageFormat.Jpeg);

                LastImageName = "~/Img/News/" + System.DateTime.Now.Day.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Year.ToString() + System.DateTime.Now.Hour.ToString() + System.DateTime.Now.Minute.ToString() + newFileName;


                newImage.Dispose();
                tmpImage.Dispose();

                tmpImage = null;
                newImage = null;
                g = null;
                return true;
            }
            catch (Exception ex)
            {
                OutputMessage = "There was an error processing the request and we have been notified. Please try again later.";
                tmpImage = null;
                newImage = null;
                g = null;
                return false;
            }
        }
        else
        {
            OutputMessage = "There was an error processing the request and we have been notified. Please try again later.";
            tmpImage = null;
            newImage = null;
            g = null;
            return false;
        }
    }

}


Please Help me.

thanks
Posted
Comments
Richard MacCutchan 19-Apr-14 4:11am    
OK, so remove it. What's the problem?
[no name] 19-Apr-14 7:58am    
So right click PhotoUploader.cs in your solution explorer and then click delete or remove. Then go through the rest of your code and fix your compilation errors.
Sunasara Imdadhusen 8-May-14 6:13am    
What is your question

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900