حفظ ملف علي الكمبيوتر save file in asp.net

حفظ ملف علي الكمبيوتر save file in asp.net

حفظ ملف علي الكمبيوتر save file in asp.net

 

بعد ان قمت برفع الملفات الي السيرفر بشكل جيد والان تريد ان يضغط العميل علي اي ملف يحفظه علي الكمبيوتر الخاص بيه

حفظ ملف علي الكمبيوتر save file in asp.net

سوف نصنع 2 فانكشن ضعهم كما هم ولا تعدل بهم شئ ..ثم اخير سوف نضع كود ثالث ينفذ ماسبق وسوف نمرر له بارمتر

1- فانكشن اولي

 

private void fileDownload(string fileName, string fileUrl)
{
Page.Response.Clear();
bool success = ResponseFile(Page.Request, Page.Response, fileName, fileUrl, 1024000);
if (!success)
Response.Write("Downloading Error!");
Page.Response.End();

}

2- فانكشن ثانية

public static bool ResponseFile(HttpRequest _Request, HttpResponse _Response, string _fileName, string _fullPath, long _speed)
{
try
{
FileStream myFile = new FileStream(_fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
BinaryReader br = new BinaryReader(myFile);
try
{
_Response.AddHeader("Accept-Ranges", "bytes");
_Response.Buffer = false;
long fileLength = myFile.Length;
long startBytes = 0;

int pack = 10240; //10K bytes
int sleep = (int)Math.Floor((double)(1000 * pack / _speed)) + 1;
if (_Request.Headers["Range"] != null)
{
_Response.StatusCode = 206;
string[] range = _Request.Headers["Range"].Split(new char[] { '=', '-' });
startBytes = Convert.ToInt64(range[1]);
}
_Response.AddHeader("Content-Length", (fileLength - startBytes).ToString());
if (startBytes != 0)
{
_Response.AddHeader("Content-Range", string.Format(" bytes {0}-{1}/{2}", startBytes, fileLength - 1, fileLength));
}
_Response.AddHeader("Connection", "Keep-Alive");
_Response.ContentType = "application/octet-stream";
_Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(_fileName, System.Text.Encoding.UTF8));

br.BaseStream.Seek(startBytes, SeekOrigin.Begin);
int maxCount = (int)Math.Floor((double)((fileLength - startBytes) / pack)) + 1;

for (int i = 0; i < maxCount; i++)
{
if (_Response.IsClientConnected)
{
_Response.BinaryWrite(br.ReadBytes(pack));
Thread.Sleep(sleep);
}
else
{
i = maxCount;
}
}
}
catch
{
return false;
}
finally
{
br.Close();
myFile.Close();
}
}
catch
{
return false;
}
return true;
}

 

3- فانكشن نضع بها متغيرات مرسلة من صفحة اخري


وفي ال page load
استدعي فنكشن

 
fileDownload(filename, Server.MapPath("/upload/" + filename));

upload هذا فولدر تخزن فيه الملفات التي ترفعها
file name هو اسم الملف .. وذلك بعد ان ترسل اسمه للصفحة

 

 

aids tests signs of hiv infection prevent hiv
chlamydia drug treatment phuckedporn.com treatment for gonorrhea
mobile spyware gps spy app android sms spy app
mobile spyware gps spy app android sms spy app
my husband and i both cheated open why i cheated on my husband
my husband and i both cheated i want to cheat on my husband why i cheated on my husband
i found out my boyfriend cheated on me gerarprieto.com cheat boyfriend
when your husband cheats maryaltmansblog.com.nobullsoftware.com why wife cheat
how to cheat on my husband letter to husband who cheated women want men
adult japanese love stories read perverted stories adult video on demand
in store walgreens coupons link prescription drugs coupons
walgreens photo promo code getwellangie.bunn-family.com walgreens coupon code for photos
online discount pharmacy open coupon for prescription
cipro xl 500mg ciprofloxacin 500mg antibiotics ciprofloxacin 500mg tablets uses
cipro xl 500mg side effects ciprofloxacin ciprofloxacin 500mg tablets uses
will my wife cheat again open wifes cheat
abortion doctors 2nd trimester abortion medical abortion nhs
pharmacy prescription discount card photo prints walgreens walgreen printable coupons
pharmacy prescription discount card free manufacturer coupons walgreen printable coupons
cipro 500mg open levofloxacin
discount prescription drug cards go coupon for prescription
abortion pill abortion pill abortion pill
lisinopril and citrus fruit lisinopril and citrus fruit lisinopril and citrus fruit
discount coupons for prescriptions cialis coupon code 2015 cialis coupon
coupons for prescriptions coupons for prescriptions new prescription coupons
discount coupon for cialis free cialis samples coupon prescription drug cards
omeprazole 1world2go.com omeprazole effet secondaire
stalevo 100 prospect stalevo 100 prospect stalevo 200 prospect
cialis 20mg cialis discount cialis 20mg
cialis 20mg cheap cialis cialis 20mg
abortion recovery link late term abortion clinics
abortion pill clinics pristineschool.com therapeutic abortion
discount coupons for cialis open cialis manufacturer coupon
cialis discount blog.pelagicfm.com cialis discount
medical abortion pill grocery discount coupons abortion centers
abortion price how much is an abortion pill abortion pill articles
vermox tablete doziranje vermox tablete nuspojave vermox suspenzija
coupons for cialis prescription discount coupons cialis coupon card
coupons for prescription medications coupons cialis cialis.com coupon
duphaston tablete duphaston forum duphaston iskustva
abortion pill services aictmkulahospital.org chemical abortion pill
cialis discount coupons aldwych-international.com discount coupons for cialis
cialis trial coupon coupon for free cialis prescription discount coupons
amoxicillin 1000 mg achi-kochi.com amoxicillin
cialis discount coupons aegdr.org cialis coupon lilly
vermox doziranje ibrahimbayir.com.tr vermox sirup cijena
cost of medical abortion abortion pill clinics in md cheap abortion pill clinics
feldene flash feldene flas feldene flash
abortion pill online teen abortion pill abortion pill costs
cialis discount coupons slb-coaching.com coupon cialis
facts on abortion pill how much are abortions abortion pill procedures
aspiration abortion arborawning.com against abortion pill
aspiration procedure abortion medications pregnancy terminate pregnancy naturally
acetazolamide migraine crownlimos.ca acetazolamide 250 mg tablets
coupon savings websites coupons and codes best sites for coupons
amoxicillin 500 mg house.raupes.net amoxicillin 1000 mg
naltrexone order naltrexone wikipedia naltrexone natural alternative
naltrexone food addiction link lose dose naltrexone
naltrexone for alcohol cravings click dr bihari ldn
naltrexone structure read naltrexone injection side effects
naltrexone effects vivitrol uk naltrexone side effects alcohol
naltrexone effects zygonie.com naltrexone side effects alcohol
naltroxine naltrexone pills naltrexone 4.5 mg buy
naltrexone implant reviews charamin.jp ldn cfs
vivitrol shot information myjustliving.com drinking while on naltrexone
what is vivitrol used for vivitrol for alcoholism naltrexone drug test
malonetta 500 jbehandling.site malonetta erstatning

نشكرك علي المشاركة