PDA

View Full Version : خواندن فایل از پوشه



marzbannia
یک شنبه 08 مرداد 1391, 19:45 عصر
با سلام خدمت هم دوستان
1)من میخواهم فایلی را از پوشه ای خوانده و آن را دانلود کنم کدی را برای آن نوشته ام ولی عمل نمی کند لطفا راهنمایی کنید.
DirectoryInfo d = new DirectoryInfo(Server.MapPath("file\\"));
foreach (FileInfo f in d.GetFiles())
{
name = f.Name;
}
ImageButton1.PostBackUrl = Server.MapPath("file\\") + name.ToString();
2)من در فرم هایم همزمان چند button دارم که با کلیک بر روی یکی از آن ها بقیه هم فعال شده و اجرا میگردند چه کار باید بکنم؟

fakhravari
یک شنبه 08 مرداد 1391, 20:20 عصر
public void DownloadFile(string filePath)
{
if (File.Exists(Server.MapPath(filePath)))
{
string strFileName = Path.GetFileName(filePath).Replace(" ", "%20");
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + strFileName);
Response.Clear();
Response.WriteFile(Server.MapPath(filePath));
Response.End();
}
}


public static string url,file;

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

if (User.Identity.IsAuthenticated)
{
file = Request.QueryString["Atach"];
url = @"../Img/File_Topik/" + file;
DownloadFile(url);
}
else
{
Response.Write("<h1><font color=red>Access Denaid Member</font></h1>");
Response.End();
}
}
}