将文件上传控制作为参数传递给方法



我想在C#中编写一个常规文件上传函数。我的网站有20多列分为选项卡,这些选项卡由近8-10个文件上传控件组成。 我想编写一种通用方法,我可以通过fileUpload控件,发布的文件&要保存的位置。如何将FileUpload控件传递到方法?

public string uploadMethod(HttpPostedFile file, <fileUpload control>, string saveLocation)
{
  //saving code
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
    uploadMethod(FileUpload1.PostedFile, <fileUpload control>, saveFolder)
}

我知道如何保存路径,但没有任何线索如何将FileUpload控件作为参数传递给方法。感谢您的帮助:)

播放后,我得到了答案。以下是解决方案...

private void uploadDoc(HttpPostedFile httpPostedFile, int filesize, string saveLocation, System.Web.UI.WebControls.FileUpload FileUpload1)
{
  //code for saving the file
}

这就是我们将参数传递给函数的方式...

uploadDoc(FileUpload1.PostedFile, filesize, saveLocation, FileUpload1);

希望这会有所帮助:)

您是否正在寻找类似的东西?

public string uploadMethod(HttpPostedFile file, FileUpload FU, string saveLocation)
{
string path = FU.FileName;
}

最新更新