コードを .docx または .pdf でアップロードできるようにしたいのですが、どうすればコードを変更できますか? 私のデータが画像の場合、私はアップロードできます
aspx.cs に私のコードがあります
protected void save_Click(object sender, EventArgs e)
{
//upload photo
int h, w; string Folder = "photo/";
h = 298; w = 765;
string asl = uploadIncResize(h, w, Folder, upload, false);
string insert = "insert into PM_formKL(title, proponent, assessor, score, upload) "
+ "values('" + Cf.StrSql(title.Text) + "','" + Cf.StrSql(proponent.Text) + "','" + Cf.StrSql(assessor.Text) + "','" + Cf.StrSql(score.Text) + "','" + asl + "')";
Db.Execute(insert);
Response.Redirect("/detail penilaian/KL/formkl.aspx");
}
// SO upload image
protected string uploadFile(string Folder, FileUpload img)
{
string upload_file = "";
try
{
string filename = Path.GetFileName(img.FileName);
string dir = Param.PathImage + Folder;
bool status = true;
while (status)
{
status = FileExists(filename, Server.MapPath("~/images/" + Folder));
if (status)
filename = getRandomFileName() + System.IO.Path.GetExtension(img.PostedFile.FileName);
}
//teaser_image.SaveAs(Server.MapPath("~/images/") + Folder + filename);
upload_file = filename;
string large = dir + filename;
img.PostedFile.SaveAs(large);
}
catch (Exception ex)
{
Js.Alert(this, "Upload status: The file could not be uploaded. The following error occured: " + ex.Message);
}
return upload_file;
}
protected string uploadIncResize(int h, int w, string Folder, FileUpload img, bool resize)
{
string upload_file = "";
try
{
if (img.PostedFile.ContentType == "image/jpeg" || img.PostedFile.ContentType == "image/png" || img.PostedFile.ContentType == "image/gif")
{
string filename = Path.GetFileName(img.FileName);
string dir = Param.PathImage + Folder;
bool status = true;
while (status)
{
status = FileExists(filename, Server.MapPath("~/images/" + Folder));
if (status)
filename = getRandomFileName() + System.IO.Path.GetExtension(img.PostedFile.FileName);
}
upload_file = filename;
string temp = dir + "(kl)" + filename;
string large = dir + filename;
img.PostedFile.SaveAs(temp);
if (resize)
{
Imgh.Crop(temp, large, h, w);
}
else
{
img.PostedFile.SaveAs(large);
}
File.Delete(temp);
Js.Alert(this, "Upload status: upload successfull.");
}
else
Js.Alert(this, "Upload status: Only JPEG , PNG or GIF files are allowed!");
}
catch (Exception ex)
{
Js.Alert(this, "Upload status: The file could not be uploaded. The following error occured: " + ex.Message);
}
return upload_file;
}
protected string getRandomFileName()
{
Random rand = new Random((int)DateTime.Now.Ticks);
int newFile = 0;
newFile = rand.Next(1, 9999999);
return newFile.ToString();
}
protected bool FileExists(string filename, string path)
{
FileInfo imageFile = new FileInfo(path + filename);
bool fileStatus = imageFile.Exists;
return fileStatus;
}