我編寫了一個使用FileUpload控件將文件上傳到數據庫的過程。使用鏈接按鈕上傳文件
bytes = new byte[] { };
filename = Path.GetFileName(FUProfile.PostedFile.FileName);
contentType = FUProfile.PostedFile.ContentType;
fileLengthInKB = FUProfile.PostedFile.ContentLength/102400;
fileName = FUProfile.PostedFile.FileName;
fileExtension = System.IO.Path.GetExtension(fileName);
fileMimeType = FUProfile.PostedFile.ContentType;
if (FUProfile.HasFile)
{
try
{
if (matchExtension.Contains(fileExtension) && matchMimeType.Contains(fileMimeType))
{
if (fileLengthInKB <= 102400)
{
using (Stream fs = FUProfile.PostedFile.InputStream)
{
using (BinaryReader br = new BinaryReader(fs))
{
bytes = br.ReadBytes((Int32)fs.Length);
clsProjects.UploadedProfile = bytes;
clsProjects.UploadedProfileCT = contentType;
clsProjects.UploadedProfileName = filename;
}
}
}
else
{
lblResult.Text = "Please choose profile file less than 1MB";
}
}
else
{
lblResult.Text = "Please choose only pdf profile file.";
}
}
catch (Exception ex)
{
lblResult.Text = "Upload status: The profile file could not be uploaded. The following error occured: " + ex.Message;
}
}
我想通過在某些窗體上使用LinkButton來做到這一點。我想通過按LinkButton來選擇一個文件(出現一個diagluebox)並將該文件保存到數據庫中。請任何想法?
是的,因爲我不想在圖形表示中使用某些表單上的FileUpload控件。 – Raja
如何打開對話框來選擇文件,然後將所選文件轉換爲InputStream,如FULogo.PostedFile.InputStream ??? – Raja