Potřeboval bych pomoc s následujícím kódem.
Pomocí ajaxu si volám ashx soubor s:
- Kód: Vybrat vše
string nazev = context.Request.Form["nazev"].ToString();
HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create("adresa");
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "xx";
postData += "&test=test";
byte[] data = encoding.GetBytes(postData);
httpWReq.Method = "POST";
httpWReq.ContentType = "application/x-www-form-urlencoded";
httpWReq.ContentLength = data.Length;
using (Stream stream = httpWReq.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
Stream httpResponseStream = response.GetResponseStream();
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
int bytesRead = 0;
FileStream fileStream = File.Create("C:\\" + nazev);
while ((bytesRead = httpResponseStream.Read(buffer, 0, bufferSize)) != 0)
{
fileStream.Write(buffer, 0, bytesRead);
}
fileStream.Close();
}
Což mi uloží soubor do C:\. Já bych ale potřeboval aby se místo uložení otevřelo klasické okno prohlížeče s: otevřít pomocí / uložit soubor. Pokoušel jsem se googlovat, žádný funkční kód se mi ale nepodařilo aplikovat.
Díky.