Fileupload Resume没有保存在文件夹中..我在哪里错了.. [英] Fileupload Resume Is Not Being Saved In Folder.. Where I Am Going Wrong..
本文介绍了Fileupload Resume没有保存在文件夹中..我在哪里错了..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我编写的代码,用来从用户那里获取简历,但文件夹data没有显示上传的文件。请帮帮我。
Here is my code which i have written to take resume from user but the folder "data" does not show the uploaded file.Please help me out.
string savePath;
savePath = Server.MapPath(.\\data\\);
private bool ValidateInput()
{
bool bSuccess;
bSuccess = true;
if (fileToRead.HasFile == false)
{
bSuccess = false;
lblMessage.Text = "Please specify a file to upload";
}
else if (chkFileEXT() == false)
{
bSuccess = false;
lblMessage.Text = "Please check your Extention of File .txt,.doc,.rtf,docx";
}
return bSuccess;
}
private bool chkFileEXT()
{
bool chkFile = false;
bool fileOK = false;
if (fileToRead.HasFile)
{
string fileExtension = null;
fileExtension = System.IO.Path.GetExtension(fileToRead.FileName).ToLower();
string[] allowedExtensions = { ".txt", ".doc",".rtf",".docx" };
for (int i = 0; i <= allowedExtensions.Length - 1; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
}
}
if (fileOK)
{
chkFile = true;
}
else
{
chkFile = false;
}
}
return chkFile;
}
private bool SaveAs(HttpPostedFile file)
{
bool bSuccess = false;
// Get the name of the file to upload.
string fileName = fileToRead.FileName;
string pathToCheck = savePath + fileName;
if ((System.IO.File.Exists(pathToCheck)))
{
bSuccess = false;
}
else
{
bSuccess = true;
}
return bSuccess;
}
protected void button1_Click(object sender, EventArgs e)
{
if (ValidateInput())
{
// Get the name of the file to upload.
string fileName = fileToRead.FileName;
// Append the name of the file to upload to the path.
//savePath += fileName
savePath += fileName;
// Call the SaveAs method to save the uploaded
// file to the specified directory.
fileToRead.SaveAs(savePath);
lblMessage.Text = "File has been uploaded";
}
}
推荐答案
检查服务器地图路径是否正确。
check ur server map path.its correct or not.
这篇关于Fileupload Resume没有保存在文件夹中..我在哪里错了..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文