HttpPostedFile and HttpPostedFileBase thing you really know?

     As you can see, you are not already in love with it, if you really look at the appearance, then you are wrong, do not believe their eyes too often is not really like what you see so simple! Please join me and see it!

     In this project, we ran into this problem, first I naive to think that they really have a relationship, not to all artifacts.

     Problems encountered: " upload pictures to the server resources " of an upload problem, just started doing did not take into account the following code:

    

public bool UploadFTP(HttpPostedFileBase file, string strFileType, int iFileLength, int Width, int Height, string Path, ref string strInfo)
{
   ............. //     
}


     I thought this was already common, and when I passed directly HttpPostedFile when the object of the error. The answer is HttpPostedFile and HttpPostedFileBase relationship does not exist.

     So I had to go at night, to check, finally found a good solution, in fact, they can still pass a bridge HttpPostedFileWrapper to transform class, HttpPostedFileWrapper : HttpPostedFileBase , HttpPostedFileWrapper code is as follows:

public  class HttpPostedFileWrapper: HttpPostedFileBase 
{ 
        // Summary:
         //      Initializes a new instance of class System.Web.HttpPostedFileWrapper.
        // 
        // Parameters:
         //    HttpPostedFile:
         //      objects through this wrapper class can access.
        // 
        // anomaly:
         //    System.ArgumentNullException:
         //      the HttpApplicationState is null. 
        public HttpPostedFileWrapper (the HttpPostedFile HttpPostedFile); 
}

 

The last solution is as follows:

 public bool UploadFTP(HttpPostedFile file, string strFileType, int iFileLength, int Width, int Height, string Path, ref string strInfo)
{ HttpPostedFileBase hpfb
= new HttpPostedFileWrapper(file) as HttpPostedFileBase; return UploadFTP(hpfb, strFileType, iFileLength, Width, Height, Path, ref strInfo); }

 A little progress every day, year cumulative progress, you go to think about it!

 Your support is my greatest motivation, if you think you can also, please give a " recommendation "!

Reproduced in: https: //www.cnblogs.com/Kummy/archive/2013/02/27/2934608.html

Guess you like

Origin blog.csdn.net/weixin_33958585/article/details/93428299