Dzwebs.Net

撰写电脑技术杂文十余年

asp.net c#版上传各种文件源代码示例下篇

Admin | 2008-5-20 18:23:03 | 被阅次数 | 7906

温馨提示!

如果未能解决您的问题,请点击搜索;登陆可复制文章,点击登陆

/// 上传杂志封面
  /// </summary>
  /// <param name="WebFile"></param>
  /// <param name="strFileName"></param>
  public void UploadCoverPic(System.Web.UI.HtmlControls.HtmlInputFile WebFile,string strFileName)
  {
   char[] spliter = {'\\'};
   string [] FileName = strFileName.Split(spliter,10);
   string FullPath = UploadCoverPath + @"\" + @"\" + FileName[FileName.Length-1];  //生成完整文件名
   WebFile.PostedFile.SaveAs(FullPath);  //保存文件
  }
  /// <summary>
  /// 上传下载杂志文件
  /// </summary>
  /// <param name="WebFile"></param>
  /// <param name="strFileName"></param>
  public void UploadDownloadPic(System.Web.UI.HtmlControls.HtmlInputFile WebFile,string strFileName)
  {
   char[] spliter = {'\\'};
   string [] FileName = strFileName.Split(spliter,10);
   string FullPath = UploadDownPath + @"\" + @"\" + FileName[FileName.Length-1];  //生成完整文件名
   WebFile.PostedFile.SaveAs(FullPath);  //保存文件
  }
  /// <summary>
  /// 上传下载杂志文件
  /// </summary>
  /// <param name="WebFile"></param>
  /// <param name="strFileName"></param>
  public void UploadBgMusicPic(System.Web.UI.HtmlControls.HtmlInputFile WebFile,string strFileName)
  {
   char[] spliter = {'\\'};
   string [] FileName = strFileName.Split(spliter,10);
   string FullPath = UploadMusicPath + @"\" + @"\" + FileName[FileName.Length-1];  //生成完整文件名
   WebFile.PostedFile.SaveAs(FullPath);  //保存文件
  }


  public void UploadLeadShowPhotoFile(System.Web.UI.HtmlControls.HtmlInputFile WebFile,string strFileName)
  {
   char[] spliter = {'\\'};
   string [] FileName = strFileName.Split(spliter,10);
   string FullPath = LeadShowPhoto + @"\" + FileName[FileName.Length-1];  //生成完整文件名
   string fromFullPath = LeadShowPhoto + @"\" +"_new"+ FileName[FileName.Length-1];  //生成完整文件名
   WebFile.PostedFile.SaveAs(fromFullPath);  //保存文件

   //加图片水印
   System.Drawing.Image image=System.Drawing.Image.FromFile(fromFullPath);
   string fixinfo=image.PixelFormat.ToString();
   if(fixinfo=="Format1bppIndexed"||fixinfo=="Format4bppIndexed"||fixinfo=="Format8bppIndexed"||fixinfo=="Undefined"||fixinfo=="DontCare"||fixinfo=="Format16bppArgb1555"||fixinfo=="Format16bppGrayScale")
   {
    WebFile.PostedFile.SaveAs(FullPath);
   }
   else
   {
    System.Drawing.Image copyImage=System.Drawing.Image.FromFile(LeadShowPhoto + @"\"+"DefaultLeadShow.gif");
    Graphics g=Graphics.FromImage(image);
    g.DrawImage(copyImage,new Rectangle(image.Width-copyImage.Width,image.Height-copyImage.Height,copyImage.Width,copyImage.Height),0,0,copyImage.Width,copyImage.Height,GraphicsUnit.Pixel);
    g.Dispose();

    //保存加水印过后的图片,删除原始图片
    //string newPath=Server.MapPath(".")+"/img/"+fileName+"_new"+extension;
    image.Save(FullPath);
    image.Dispose();
    if(File.Exists(fromFullPath))
    {
     File.Delete(fromFullPath);
    }
   }
  }


 }

}


该杂文来自: 网站开发杂文

上一篇:asp.net c#版上传各种文件源代码示例中篇

下一篇:网站图片附盗链asp.net(c#)源代码

网站备案号:

网站备案号:滇ICP备11001339号-7

版权属性:

Copyright 2007-2021-forever Inc. all Rights Reserved.

联系方式:

Email:dzwebs@126.com QQ:83539231 访问统计