Exemplo n.º 1
0
        /// <summary>
        /// Open the select file dialog, and begin uploading files.
        /// </summary>
        private void SelectUserFiles()
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Multiselect = MultiSelect;

            try
            {
                // Check the file filter (filter is used to filter file extensions to select, for example only .jpg files)
                if (!string.IsNullOrEmpty(FileFilter))
                {
                    ofd.Filter = FileFilter;
                }
            }
            catch (ArgumentException ex)
            {
                // User supplied a wrong configuration filter
                throw new Exception("Wrong file filter configuration.", ex);
            }

            if (ofd.ShowDialog() == true)
            {
                foreach (FileInfo file in ofd.Files)
                {
                    // create an object that represents a file being uploaded
                    UserFile userFile = new UserFile();
                    userFile.FileName          = file.Name;
                    userFile.FileStream        = file.OpenRead();
                    userFile.UIDispatcher      = this.Dispatcher;
                    userFile.HttpUploader      = true;
                    userFile.UploadHandlerName = UploadHandlerPath;
                    userFile.ChunkSizeMB       = ChunkSizeMB;

                    // check the file size limit
                    if (MaxFileSizeKB == -1 || userFile.FileSize <= MaxFileSizeKB * 1024)
                    {
                        _files.Add(userFile);
                    }
                    else
                    {
                        HtmlPage.Window.Alert(userFile.FileName + " exceeds the maximum file size of " + (MaxFileSizeKB).ToString() + "KB.");
                    }
                }
            }

            // start uploading the selected files
            if (_files.Count > 0)
            {
                OnUploadStarted();
                _files.UploadFiles();
            }
        }
Exemplo n.º 2
0
        public HttpFileUploader(UserFile file, string httpHandlerPath, long ChunkSizeMB)
        {
            _file = file;

            if (ChunkSizeMB > 0)
                ChunkSize = 1024 * 1024 * ChunkSizeMB;

            _dataLength = _file.FileSize;
            _dataSent = 0;

            if (string.IsNullOrEmpty(httpHandlerPath))
                throw new ArgumentException("A valid http handler was not specified.");

            UriBuilder builder = new UriBuilder(Application.Current.Host.Source.Scheme, Application.Current.Host.Source.Host,
                Application.Current.Host.Source.Port, httpHandlerPath);

            UploadUrl = builder.Uri.ToString();
        }
Exemplo n.º 3
0
        public HttpFileUploader(UserFile file, string httpHandlerPath, long ChunkSizeMB)
        {
            _file = file;

            if (ChunkSizeMB > 0)
            {
                ChunkSize = 1024 * 1024 * ChunkSizeMB;
            }

            _dataLength = _file.FileSize;
            _dataSent   = 0;

            if (string.IsNullOrEmpty(httpHandlerPath))
            {
                throw new ArgumentException("A valid http handler was not specified.");
            }

            UriBuilder builder = new UriBuilder(Application.Current.Host.Source.Scheme, Application.Current.Host.Source.Host,
                                                Application.Current.Host.Source.Port, httpHandlerPath);

            UploadUrl = builder.Uri.ToString();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Open the select file dialog, and begin uploading files.
        /// </summary>
        private void SelectUserFiles()
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Multiselect = MultiSelect;

            try
            {
                // Check the file filter (filter is used to filter file extensions to select, for example only .jpg files)
                if (!string.IsNullOrEmpty(FileFilter))
                    ofd.Filter = FileFilter;
            }
            catch (ArgumentException ex)
            {
                // User supplied a wrong configuration filter
                throw new Exception("Wrong file filter configuration.", ex);
            }

            if (ofd.ShowDialog() == true)
            {
                foreach (FileInfo file in ofd.Files)
                {
                    // create an object that represents a file being uploaded
                    UserFile userFile = new UserFile();
                    userFile.FileName = file.Name;
                    userFile.FileStream = file.OpenRead();
                    userFile.UIDispatcher = this.Dispatcher;
                    userFile.HttpUploader = true;
                    userFile.UploadHandlerName = UploadHandlerPath;
                    userFile.ChunkSizeMB = ChunkSizeMB;

                    // check the file size limit
                    if (MaxFileSizeKB == -1 || userFile.FileSize <= MaxFileSizeKB * 1024)
                        _files.Add(userFile);
                    else
                        HtmlPage.Window.Alert(userFile.FileName + " exceeds the maximum file size of " + (MaxFileSizeKB).ToString() + "KB.");
                }
            }

            // start uploading the selected files
            if (_files.Count > 0)
            {
                OnUploadStarted();
                _files.UploadFiles();
            }
        }
Exemplo n.º 5
0
 public FileUploadedEventArgs(UserFile file) : this(file.Guid, file.FileName, file.FileSize)
 {
 }