Webapi upload Service, rename according to filename, create folder according to Path
/// <summary> ///Uploading Files/// </summary> /// <returns></returns>[HttpPost, Route ("Upload")] PublicIhttpactionresult UploadFile () {stringDefaultPath = configurationmanager.appsettings["CM. FilePath"]; stringPath = httpcontext.current.request["Path"]; stringFileName = httpcontext.current.request["FileName"]; stringFullPath = DefaultPath +"\\"+ path;//Upload Path if(!directory.exists (FullPath)) {directory.createdirectory (FullPath); } List<dictionary<string, string>> filenames =NewList<dictionary<string, string>>(); Httpfilecollection Files=HttpContext.Current.Request.Files; foreach(stringKeyinchfiles. AllKeys) {httppostedfile file1=Files[key]; if(string. IsNullOrEmpty (File1. FileName) = =false) {Dictionary<string, string> dic =Newdictionary<string,string>(); if(string. Isnullorwhitespace (fileName) = =false) {
Rename the file1. SaveAs (FullPath+"\\"+fileName); Dic. ADD (key, Path+"\\"+fileName); } Else{file1. SaveAs (FullPath+"\\"+File1. FileName); Dic. ADD (key, Path+"\\"+File1. FileName); } filenames. ADD (DIC); }} serverresponse Response=NewServerresponse (filenames); returnOk (response); }
Webapi upload Service, can be renamed, can create folders