我检查是否正在从FileUpload获取一个包含数据的文件,但是当我尝试将其保存到服务器中时,创建的文件是空的。我做错什么了?
一开始我有UpdatePanel,但现在没有任何更新面板。
string string1, string2, string3;
bool bool1= false, bool2= false, bool3= false;
using (StreamReader reader = new StreamReader(fuSubirPlantilla.PostedFile.InputStream))
{
string contenidoPlantilla = reader.ReadToEnd();
bool1= contenidoPlantilla.Contains("[tag1]");
bool2= contenidoPlantilla.Contains("[tag2]");
bool3= contenidoPlantilla.Contains("[tag3]");
}
if (bool1 && bool2 && bool3)
{
string1 = dropdown1.SelectedValue;
string2 = dropdown2.SelectedValue;
string3 = dropdown3.SelectedValue;
string filename= "filename1_" + string1 + "_" + string2 + "_" + string3 + ".html";
string folder = Server.MapPath( "~/XML_MI/Common/").Replace("/", "\\");
// Me aseguro de que termine en \\
folder = folder.EndsWith("\\") ? folder : folder + "\\";
// Antes de guardar el archivo
string folderFilePath = $"{folder}{filename}";
fuSubirPlantilla.SaveAs(folderFilePath);
//Stream stream = fuSubirPlantilla.PostedFile.InputStream;
//using (FileStream fileStream = File.Create(folderFilePath))
//{
// stream.CopyTo(fileStream);
//}
}
else
{
// Error
}
using (FileStream fileStream = File.Create(folderFilePath))
{
stream.CopyTo(fileStream);
}
这个问题与我在开始时读取所有流有关[
reader.ReadToEnd()