62,074
社区成员
发帖
与我相关
我的任务
分享
string Book_Code = Request["Book_Code"].ToString();
string image_full_name = Request["image_full_name"].ToString();
string image_name = image_full_name.Substring(0, image_full_name.IndexOf(@"."));
string path = Server.MapPath("../../Books_Data/" + Book_Code + "/");
string txt = TextBox1.Text;
txt = txt.Replace("'","''");
System.IO.File.Delete(Server.MapPath("../../Books_Data/" + Book_Code + "/" + image_name + ".txt"));//这句报错
System.IO.StreamWriter swobj = System.IO.File.AppendText(path+ "/" + image_name+".txt");
swobj.WriteLine(txt);
swobj.Flush();
swobj.Dispose();
swobj.Close();
System.IO.File.Delete(Server.MapPath("../../Books_Data/" + Book_Code + "/" + image_name + ".txt"));//这句报错
try
{
System.IO.File.Delete(filename);//这句报错
}
catch(Exception e){ //异常处理}
string Book_Code = Request["Book_Code"].ToString();
string image_full_name = Request["image_full_name"].ToString();
string image_name = image_full_name.Substring(0, image_full_name.IndexOf(@"."));
string path = Server.MapPath("../../Books_Data/" + Book_Code + "/");
string txt = TextBox1.Text;
txt = txt.Replace("'", "''");
//-----------------------
string filename = Server.MapPath("../../Books_Data/" + Book_Code + "/" + image_name + ".txt");
if (System.IO.File.Exists(filename)) //一般删除文件要判断文件是否存在,如果不存在当然删除不了
{
System.IO.File.Delete(filename);//这句报错
}
/*
//如果可能有多个用户同时访问,还要考虑进程同步如下:
//先定义全局变量lockFile
private static readonly object lockFile = new object();//全局变量
lock (lockFile)
{
string filename = Server.MapPath("../../Books_Data/" + Book_Code + "/" + image_name + ".txt");
if (System.IO.File.Exists(filename)) //一般删除文件要判断文件是否存在,如果不存在当然删除不了
{
try
{
System.IO.File.Delete(filename);//这句报错
}
}
}
* */
//------------------------
System.IO.StreamWriter swobj = System.IO.File.AppendText(path + "/" + image_name + ".txt");
swobj.WriteLine(txt);
swobj.Flush();
swobj.Dispose();
swobj.Close();