Prabu Spark Ответов: 6

Как скачать несколько файлов в asp.net в форме нагрузки?


Привет сэр,
Скажите мне шаги для загрузки нескольких файлов с помощью asp.net с#. Я сохранил имена файлов в строковом массиве и ввел цикл for, но цикл for идет только один раз. я приложил код для вашей справки. Пожалуйста, дайте мне решение этой проблемы.


[Примечание: из-за Response.End() он не будет переходить к следующему приращению значения в цикле for]


protected void Page_Load(object sender, EventArgs e)
   {
       string[] values = { "setup1.apk", "setup1.apk" };

       for (int i = 0; i < values.Length; i++)
       {
           downloadfiles(values[i]);
       }

   }

   private void downloadfiles(string filename)
   {
       Response.Cache.SetCacheability(HttpCacheability.NoCache);
       Response.ClearContent();
       Response.Clear();
       Response.ContentType = "application/msi";
       Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename);
       Response.TransmitFile(Server.MapPath("~/jad/") + filename);
     
       Response.End();

   }

6 Ответов

Рейтинг:
2
Рейтинг:
2

Prabu Spark

Привет сэр,
Если я удалю Response.End() в функциях downloadfiles, ни один файл не будет загружен для меня.


Рейтинг:
2

Saher Mohamed Mostafa

Я ее разгадал
создайте файл download.asp в том же каталоге, что и ваша главная страница / скрипт
и вставьте в него приведенный ниже код

<%OPTION EXPLICIT%> 

<%
dim pathx 
pathx  = trim(Request.QueryString("file"))
downloadfile(pathx)
 Sub downloadfile(pathx_file)
  
	  dim paths 
	  paths = Replace(pathx_file,"file_splitter","\\\")'
pathx_file = paths
dim downfile, stream ,lSize
	Dim fsox
	const CHUNK = 3670016 
	Response.Clear
	set fsox = CreateObject("Scripting.FileSystemObject")
	Set downfile = fsox.GetFile(pathx_file)
	set stream = Server.CreateObject("ADODB.Stream")	
	response.ContentType = "application/octet-stream"
	response.AddHeader "Content-Disposition", "attachment; filename=" & downfile.Name  
	stream.Open
	stream.Type = 1
	stream.LoadFromFile(downfile.Path)
	lSize = stream.Size
	Response.AddHeader "Content-Length", lSize
	Do While Not stream.EOS
	Response.BinaryWrite stream.Read(CHUNK)
	Response.Flush
	Loop
	stream.Close
	set stream = Nothing
	set downfile = Nothing
	Response.End 
End Sub
%>




Затем на вашей главной странице зацикливайтесь на файлах
for each i in list
	 'i.Path  the path for file 
  dim paths 'replace the slash because it disappears  then will be undo in download ' script 
	  paths = Replace(i.path,"\","file_splitter") 

  
	  Response.Write("<" & "script>" & "window.open('" & "download.asp?file=" & paths & "');"& "<" & "/script>")
	
next


с уважением ;
Сахер Синий Орел


Рейтинг:
0

kk2014

Привет,

вы отладили свой код? если вы отладите свой код вы найдете

Response.End();
в
downloadfiles
() функция. прокомментируйте его, и он повторит цикл во второй раз.

спасибо