图片上传路径未在文件夹中上传

时间:2014-06-24 07:42:52

标签: c# asp.net image-uploading

我在尝试上传文件夹上的图片并点击上传时出现问题,图片未保存在“UploadedFiles”文件夹中。“UploadedFiles”文件夹仍为空,不包含任何图片。

这是我保存的图片的项目目录,如果有帮助的话应该去:

// C:\ Users \ Drake \ Documents \ Visual Studio 2013 \ Projects \ DigitalWaterMarkTest \ DigitalWaterMarkTest \ UploadFiles

protected void btnSave_Click(object sender, EventArgs e)
{
    // Here We will upload image with watermark Text
    string fileName = Guid.NewGuid() + Path.GetExtension(FU1.PostedFile.FileName);
    Image upImage = Image.FromStream(FU1.PostedFile.InputStream);
    upImage = ResizeBitmap((Bitmap)upImage, 400, 400);//new width
    using (Graphics g = Graphics.FromImage(upImage))            
    {
        // For Transparent Watermark Text 
        int opacity = 128; // range from 0 to 255

        //SolidBrush brush = new SolidBrush(Color.Red);
        SolidBrush brush = new SolidBrush(Color.FromArgb(opacity, Color.Black));
        SolidBrush brush2 = new SolidBrush(Color.FromArgb(opacity, Color.Red));

        Font font = new Font("Arial", 15);
        g.DrawString(txtWatermarkText.Text.Trim(), font, brush, new PointF(80,160));
        g.DrawString(txtWatermarkText.Text.Trim(), font, brush2, new PointF(200, 250));

        upImage.Save(Path.Combine(Server.MapPath("~/UploadFiles"), fileName));
        Image1.ImageUrl = "~/UploadFiles" + "//" + fileName;
    }
}

0 个答案:

没有答案