private string Upload(int userId)
    {
        const int maxImageLength = 1000000;
        string    fileName       = "";
        string    filePath       = fileUpload.FileName;

        if (filePath.Trim().Length > 0)
        {
            PostedImage          postedImage = new PostedImage(fileUpload, maxImageLength);
            System.Drawing.Image image       = postedImage.FitImage(new Size(128, 128));
            string      path        = PathUtils.BaseDirectory + "Images\\Users\\";
            string      ext         = postedImage.Extension;
            ImageFormat imageFormat = ImageFormat.Gif;

/*			switch (ext)
 *                      {
 *                              case ".gif":
 *                                      imageFormat = ImageFormat.Gif;
 *                                      break;
 *                              case ".png":
 *                                      imageFormat = ImageFormat.Png;
 *                                      break;
 *                      }*/
            fileName = Hash(userId) + ext;
            image.Save(path + fileName, imageFormat);
            //			lblInfo.Text = string.Format("‘айлы сохранены: {0}, {1}, {2}", fileName, fileName1, fileName2);
            lblPicture.Text = fileName;
        }
        return(fileName);
    }
    private void Upload()
    {
        const int maxImageLength = 15000000;
        string    fileName       = Path.GetFileName(fileUpload.FileName);

        if (fileName.Trim().Length > 0)
        {
            PostedImage          postedImage = new PostedImage(fileUpload, maxImageLength);
            System.Drawing.Image image       = postedImage.FitImage(new Size(196, 196));
            ImageFormat          imageFormat = ImageFormat.Jpeg;
            string ext = postedImage.Extension;
            switch (ext)
            {
            case ".gif":
                imageFormat = ImageFormat.Gif;
                break;

            case ".png":
                imageFormat = ImageFormat.Png;
                break;
            }
            fileName = postedImage.FileNameWithoutExtension + ext;
            image.Save(PathUtils.BaseDirectory + "Gallery\\" + fileName, imageFormat);
            lblLogo.Text = fileName;
        }
    }
예제 #3
0
    private bool Upload()
    {
        const int maxImageLength = 15000000;
        string    filePath       = fileUpload.FileName;

        if (filePath.Trim().Length > 0)
        {
            PostedImage postedImage = new PostedImage(fileUpload, maxImageLength);

            System.Drawing.Image image  = postedImage.FitImage(new Size(512, 512));
            System.Drawing.Image image1 = postedImage.FitImage(new Size(196, 196));
            System.Drawing.Image image2 = postedImage.FitImage(new Size(256, 256));
            string      path            = PathUtils.BaseDirectory + "Gallery\\";
            ImageFormat imageFormat     = ImageFormat.Jpeg;
            string      ext             = postedImage.Extension;
            switch (ext)
            {
            case ".gif":
                imageFormat = ImageFormat.Gif;
                break;

            case ".png":
                imageFormat = ImageFormat.Png;
                break;
            }
            string fileName  = postedImage.FileNameWithoutExtension + ext;
            string fileName1 = "p1_" + fileName;
            string fileName2 = "p2_" + fileName;
            image.Save(path + fileName, imageFormat);
            image1.Save(path + fileName1, imageFormat);
            image2.Save(path + fileName2, imageFormat);
//			lblInfo.Text = string.Format("Файлы сохранены: {0}, {1}, {2}", fileName, fileName1, fileName2);
            tbFilename.Text = fileName;
            return(true);
        }
        else
        {
            lblInfo.ForeColor = Color.Red;
            lblInfo.Text      = "Выберете файл для загрузки";
            return(false);
        }
    }