Example #1
0
        private bool SetSavePath(RequestLite requestLite)
        {
            var    dir  = "~" + Path.GetFileNameWithoutExtension(requestLite.CsvFile);
            string path = Path.Combine(Environment.CurrentDirectory, dir);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            using (var dlg = new CommonOpenFileDialog())
            {
                dlg.InitialDirectory = path;
                dlg.IsFolderPicker   = true;
                dlg.Multiselect      = false;
                dlg.Title            = "Download to";

                if (dlg.ShowDialog() != CommonFileDialogResult.Ok)
                {
                    return(false);
                }

                requestLite.OutputDir = dlg.FileName;
            }
            return(true);
        }
Example #2
0
        private bool CheckPrerequisites(out RequestLite requestLite, out string msg)
        {
            requestLite = new RequestLite {
                CsvFile = tbFileSelected.Text
            };
            msg = null;

            //check csv file
            if (!File.Exists(requestLite.CsvFile))
            {
                msg = "csv file not found!";
                return(false);
            }
            if (Path.GetExtension(requestLite.CsvFile).ToLower() != ".csv")
            {
                msg = "only csv file allowed!";
                return(false);
            }
            try
            {
                using (var fs = File.OpenRead(requestLite.CsvFile))
                {
                }
            }
            catch (IOException e)
            {
                msg = e.Message;
                return(false);
            }

            //all passed
            return(true);
        }