예제 #1
0
        public ActionResult Index()
        {
            try {
                string sessionID    = "pathDownload" + Request.QueryString["plc"];
                string network_path = Session[sessionID].ToString();
                Session["network_path"] = network_path;

                List <string> filesToView = new List <string>();
                int           i           = 0;
                List <string> masks       = new List <string>();
                List <string> masksNames  = new List <string>();

                List <FileForDownload> model = new List <FileForDownload>();
                FileHelper             FH    = new FileHelper();
                masksNames = FH.selectMasksNames((int)Session["id"]);
                masks      = FH.selectMasks((int)Session["id"], Roles.GetRolesForUser());
                foreach (string mask in masks)
                {
                    FileForDownload FFD = new FileForDownload();
                    if (masksNames[i] != "")
                    {
                        FFD.maskName = masksNames[i];
                    }
                    FFD.pathes = FH.findFilesOnServer(network_path, mask);
                    FFD.files  = new List <string>();
                    foreach (string path in FFD.pathes)
                    {
                        string fileName = path.Substring(path.LastIndexOf('/') + 1);
                        FFD.files.Add(fileName);
                    }
                    if (FFD.files == null)
                    {
                        ViewBag.warning = "No files has been found";
                        filesToView.Add("No files has been found");
                    }
                    i++;
                    model.Add(FFD);
                }
                return(View(model));
            }
            catch {
                ViewBag.message = "Problem with finding downloads to this bakery.";
                return(View());
            }
        }
예제 #2
0
파일: ChatForm.cs 프로젝트: ilia844/KSiS
        private async void btDownloadFile_Click(object sender, EventArgs e)
        {
            int selectedFileIndex = lbMessageFiles.SelectedIndex;

            if (selectedFileIndex > -1 && selectedFileIndex < lbMessageFiles.Items.Count)
            {
                int             fileId          = communityData.Dialogs[MatchingDialogs[CurrentDialog]].MessagesHistory[CurrentMessageId].AttachedFiles[selectedFileIndex];
                FileForDownload fileForDownload = await fileSharingClient.DownloadFile(fileId, FileSharingServerUrl);

                if (fileForDownload != null)
                {
                    SaveFileDialog saveDialog = new SaveFileDialog();
                    saveDialog.FileName = fileForDownload.FileName;
                    if (saveDialog.ShowDialog() == DialogResult.OK)
                    {
                        string filePath = saveDialog.FileName;
                        using (FileStream fileStream = new FileStream(filePath, FileMode.Create))
                        {
                            fileStream.Write(fileForDownload.FileBytes, 0, fileForDownload.FileBytes.Length);
                        }
                    }
                }
            }
        }