Exemple #1
0
        private void download(object sender, RoutedEventArgs e)
        {
            Button         button = sender as Button;
            FileFromSerwer file   = (FileFromSerwer)button.DataContext;

            var dialog = new SaveFileDialog();

            dialog.FileName = file.name;
            dialog.Filter   = "PDF (*.pdf)|*.pdf|wszystkie pliki (*.*)|*.*|txt (*.txt)|*.txt|rar (*.rar)|*.rar|docx (*.docx)|*.docx|plikmagnetyczny (*.magnetic)|*.magnetic";
            var result = dialog.ShowDialog(); //shows save file dialog

            try
            {
                var wClient = new WebClient();
                wClient.DownloadFile("http://" + file.download_link, dialog.FileName);
            }
            catch (Exception exc) { MessageBox.Show("wystapil problem podczas sciagania pliku"); }
        }
Exemple #2
0
        private void downloadMagnet(object sender, RoutedEventArgs e)
        {
            Button         button = sender as Button;
            FileFromSerwer file   = (FileFromSerwer)button.DataContext;

            var dialog = new SaveFileDialog();

            dialog.FileName = file.name + ".magnetic";
            dialog.Filter   = "plik magnetyczny (*.magnetic)|*.magnetic|wszystkie pliki (*.*)|*.*";
            var result = dialog.ShowDialog(); //shows save file dialog

            //przygotowanie wiadomosci do wyslania
            NameValueCollection outgoingQueryString = HttpUtility.ParseQueryString(String.Empty);

            outgoingQueryString.Add("token", container.sessiontoken);
            outgoingQueryString.Add("file_id", file.id);
            string postdata = outgoingQueryString.ToString();

            try
            {
                //wysylanie wiadomosci
                WebRequest request = WebRequest.Create(container.addresweb + "/api/download_magnet/");
                request.Method = "POST";
                byte[] byteArray = Encoding.UTF8.GetBytes(postdata);
                request.ContentType   = "application/x-www-form-urlencoded";
                request.ContentLength = byteArray.Length;
                Stream dataStream = request.GetRequestStream();
                dataStream.Write(byteArray, 0, byteArray.Length);
                dataStream.Close();

                //otrzymana odpowiedz
                WebResponse response = request.GetResponse();
                dataStream = response.GetResponseStream();
                using (Stream output = System.IO.File.OpenWrite(dialog.FileName))
                    using (Stream input = dataStream)
                    {
                        input.CopyTo(output); //zapisywanie pliku
                    }
            }
            catch (Exception exc) { MessageBox.Show("Wystapil problem podczas polaczenia z serwerem"); }
        }
Exemple #3
0
        private void delete(object sender, RoutedEventArgs e)
        {
            Button         button = sender as Button;
            FileFromSerwer file   = (FileFromSerwer)button.DataContext;

            //przygotowanie wiadomosci do wyslania
            NameValueCollection outgoingQueryString = HttpUtility.ParseQueryString(String.Empty);

            outgoingQueryString.Add("token", container.sessiontoken);
            outgoingQueryString.Add("file_id", file.id);
            string postdata = outgoingQueryString.ToString();

            try
            {
                //wysylanie wiadomosci
                WebRequest request = WebRequest.Create(container.addresweb + "/api/del_file/");
                request.Method = "POST";
                byte[] byteArray = Encoding.UTF8.GetBytes(postdata);
                request.ContentType   = "application/x-www-form-urlencoded";
                request.ContentLength = byteArray.Length;
                Stream dataStream = request.GetRequestStream();
                dataStream.Write(byteArray, 0, byteArray.Length);
                dataStream.Close();

                WebResponse response = request.GetResponse();
                dataStream = response.GetResponseStream();
                StreamReader reader             = new StreamReader(dataStream);
                string       responseFromServer = reader.ReadToEnd();
                reader.Close();
                dataStream.Close();
                response.Close();
                JObject json = JObject.Parse(responseFromServer);
                container.filelist.Remove(file);
                tbFile.DataContext = container.filelist;
            }catch (Exception exc) { MessageBox.Show("Wystapil problem podczas polaczenia z serwerem"); }
        }