PDA

View Full Version : ایجاد فایل روی سرور



amir_king2_2
دوشنبه 13 بهمن 1382, 15:59 عصر
سلام.
من میخوام یک فایل تو دایرکتوری root سایتم با استفاده از دستورات asp.net با نام a.htm بوجود بیارم. (با #C یا Vb.net).
از دستور زیر استفاده میکنم ولی جواب نمیده. لطفا راهنمایی کنید.


System.IO.File.Create("a.txt");
یا

System.IO.File.Create("www.site.com/a.txt");
یا

System.IO.File.Create(Server.MapPath("a.txt"));
یا

System.IO.File.Create(Server.MapPath("www.site.com/a.txt"));
ولی هیچکدوم جواب نداد. :(

Vahid_Nasiri
دوشنبه 13 بهمن 1382, 18:56 عصر
من برای لاگ کردن خطاهای اتفاق افتاده در برنامه و مطالعه ی بعدی آنها کلاس زیر را نوشته ام که خطا ها را ( در صورتیکه در هر جایی از برنامه از این توابع استفاده کنید ) درون یک فایل متنی روی سرور ذخیره می کند. امیدوارم مفید باشد :wink:



using System;
using System.Diagnostics;
using System.IO;
using System.Web;
using System.Text;



namespace e_forum
{
/// <summary>
/// Summary description for clsDebugLogging.
/// </summary>
public class clsDebugLogging
{
public clsDebugLogging()
{
//
// TODO: Add constructor logic here
//
}

public void wirteErrorToLogFile(object m_value , string function_name)
{

try
{
string filePath = HttpContext.Current.Server.MapPath("app_error.log");
FileInfo logFile = new FileInfo(filePath);

if (logFile.Exists)
{
if (logFile.Length >= 100000)
File.Delete(filePath);
}

FileStream fs = new FileStream(filePath, FileMode.Append , FileAccess.Write );

StreamWriter w = new StreamWriter(fs);
w.BaseStream.Seek(0, SeekOrigin.End);

w.Write("\nLog Entry : ");
w.Write("{0} {1} \n\n", DateTime.Now.ToLongTimeString(),
DateTime.Now.ToLongDateString());

w.Write(function_name + "\n\n");
w.Write(m_value.ToString() + "\n");
w.Write("------------------------------------\n");

w.Flush();

w.Close();
}
catch
{
//
}

}
}
}

Vahab
دوشنبه 13 بهمن 1382, 22:01 عصر
برای من که مفید بود