string Route = @"D:\ksy\ksy\WebSite1\";//文件地址
string File_name = "userfaceqwe.png";
string New_File_name = "000.png";
if (System.IO.File.Exists(Route+File_name))
{
System.IO.File.Move(Route + File_name, Route + New_File_name);
}
string File_name = "userfaceqwe.png";
string New_File_name = "000.png";
if (System.IO.File.Exists(Route+File_name))
{
System.IO.File.Move(Route + File_name, Route + New_File_name);
}
写日志用的
1 string mapPath = @"/Log1"; 2 string fileName = string.Format("{0}/{1}.txt", mapPath, DateTime.Now.ToString("yyyy-MM-dd")); 3 List<string> messages = new List<string>(); 4 5 messages.Add("-------------------------------------------------------------"); 6 messages.Add(" 反反复复付付付付付付付付付:" + Request.Form[" "] + ",状态:" + Request.QueryString["trade_status"] + " 宝 号:" + Request.Form[" "] + "总 " + Request.Form["total_fee"] + "responseTxt=" + responseTxt + " notify_url_log:sign=" + Request.Form["sign"] + "&mysign=" + mysign + " notify回来的参数:"); 7 foreach (string pastring in sArrary) 8 { 9 messages.Add(pastring); 10 } 11 12 if (Directory.Exists(Server.MapPath(urlconvertor(mapPath))) == false)//如果不存在就创建file文件夹 13 { 14 Directory.CreateDirectory(Server.MapPath(urlconvertor(mapPath)));//吧路径转成相对路径 15 } 16 File.AppendAllLines(HttpContext.Current.Server.MapPath(fileName), messages, System.Text.Encoding.UTF8);
1 private string urlconvertor(string imagesurl1) 2 { 3 string tmpRootDir = Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString());//获取程序根目录 4 string imagesurl2 = imagesurl1.Replace(tmpRootDir, ""); //转换成相对路径 5 imagesurl2 = imagesurl2.Replace(@"\", @"/"); 6 return imagesurl2; 7 }