Create an empty Web site, create a uploadfile.aspx item,
When the server reports a 500 error, check to see if the file save path exists
1 protected voidPage_Load (Objectsender, EventArgs e)2 {3 foreach(stringFinchRequest.Files.AllKeys)4{//to pass in a new file on the client5Httppostedfile file =Request.files[f];6 //A new file name is passed in to the client7 stringDirectory = request.querystring["D"];8 stringfilename = request.querystring["N"];9 //file. SaveAs (Server.MapPath (". /reportfile/"+ filename + file. Filename.substring (file. Filename.indexof (".") ));Ten stringPath =string. Format (@"g:\reportfile\{0}\", directory); One if(!directory.exists (path)) {directory.createdirectory (path);} AFile. SaveAs (path +filename); - } -}
In WPF
1 usingform =System.Windows.Forms;2 Private Const stringDirectory ="0123";3 Public voidUpload (stringfile)4 {5FileInfo info =NewFileInfo (file);6 stringURL =string. Format ("Http://192.168.31.118:54040/uploadfile.aspx?d={0}&n={1}", directory, info. Name);7WebClient client =NewWebClient ();8Client. Credentials = CredentialCache.DefaultCredentials;//Gets or sets the network credentials that are sent to the host and used for authentication requests9Client. Uploadfileasync (NewUri (URL), file);TenClient. uploadfilecompleted + =NewUploadfilecompletedeventhandler (result_uploadfilecompleted); One } A Private voidResult_uploadfilecompleted (Objectsender, UploadFileCompletedEventArgs e) - { - if(E.error! =NULL) the { -MessageBox.Show ("Upload failed:"+e.error.message); - } - Else + { -MessageBox.Show ("Upload Success! "); + } A } at - Private voidUploadfile_click (Objectsender, RoutedEventArgs e) - { -Form. OpenFileDialog _dialog =Newform. OpenFileDialog (); -_dialog. MultiSelect =true; - if(_dialog. ShowDialog () = =form. DialogResult.OK) in { - string[] _files =_dialog. FileNames; to if(_files! =NULL&& _files. Length >0) + { - foreach(varIteminch_files) the { * Upload (item); $ }Panax Notoginseng } - } the}
WPF uploading files to the server