上传:

 


        protected string UpPicFile(System.Web.UI.WebControls.FileUpload FileUpControl, ref string fileType)
        {
            
if (FileUpControl.HasFile)
            {
                
string strErr = "";

                
#region 验证
                
if (FileUpControl.PostedFile == null)
                {
                    strErr 
+= "对不起,上传文件不能为空!\\n";
                }
                
int size = FileUpControl.PostedFile.ContentLength;//大小
                if (size < 1)
                {
                    strErr 
+= "对不起,上传文件不能为空!\\n";
                }
                
if (size > 10485760)
                {
                    strErr 
+= "对不起,文件大小不能大于10M!\\n";
                }
                
if (strErr != "")
                {
                    QDHotel.Common.MessageBox.Show(
this, strErr);
                    
return null;
                }
                
#endregion

                
string UploadFileType = FileUpControl.PostedFile.ContentType;
                
string UpFileName = FileUpControl.FileName;
                
string picname = DateTime.Now.ToString("yyyyMMddHHmmss"+ UpFileName;
                fileType 
= UploadFileType;
                
#region 不同类型UploadFileType

                
switch (UploadFileType)
                {
                    
case "image/gif":
                    
case "image/bmp":
                    
case "image/pjpeg":
                        {
                            Stream StreamObject 
= FileUpControl.PostedFile.InputStream;//建立数据流对像
                            System.Drawing.Image myImage = System.Drawing.Image.FromStream(StreamObject);
                            
int w = myImage.Width;
                            
int h = myImage.Height;
                        }
                        
break;

                    
case "application/msword":
                    
case "application/vnd.ms-excel":
                        
break;


                    
default:
                        strErr 
+= "对不起,不允许该文件格式上传!\\n";
                        
break;
                }
                
#endregion

                
if (strErr != "")
                {
                    QDHotel.Common.MessageBox.Show(
this, strErr);
                    
return null;
                }

                
try
                {
                    
string path = ADUploadFolder + picname;
                    path 
= Server.MapPath(path);
                    FileUpControl.PostedFile.SaveAs(path);
                    
return picname;
                }
                
catch //(Exception ex)
                {
                    
return null;
                }

            }
            
else
            {
                
return null;
            }
        }
        
#endregion

 

 

下载

图片上传/下载,DOC.xls文档下载的方法   private void ViewImage(string fileType, string fileName, bool forceDownload)
        }

相关文章:

  • 2021-11-29
  • 2021-09-23
  • 2021-12-04
  • 2021-08-14
  • 2022-02-01
猜你喜欢
  • 2021-12-22
  • 2021-07-08
  • 2021-07-08
  • 2022-12-23
  • 2022-12-23
  • 2021-06-15
  • 2022-12-23
相关资源
相似解决方案