Read files under a folder
Public stringreadimagespaths () {stringresult =string. Empty; Try { stringPath =System.IO.Directory.GetCurrentDirectory (); DirectoryInfo Files=NewDirectoryInfo (path+@"\images"); Fileinfo[] FileInfo=files. GetFiles (); foreach(FileInfo fileinchFileInfo) { //result + files [email protected] "\" + file. Name + ";";Result + = file. Name +";"; } } Catch(Exception ex) {_log. Error (ex); } returnresult; }
Download the picture according to the file name and save as:
PublicStream Downloadimage (stringname) { stringPath =System.IO.Directory.GetCurrentDirectory (); DirectoryInfo Files=NewDirectoryInfo (path +@"\images"); Fileinfo[] FileInfo=files. GetFiles (); FileStream filecontent; Byte[] Filebyte=Newbyte[1]; foreach(FileInfo fileinchFileInfo) { if(file. Name = =name) { stringfilepath = files +@"\"+name; Filecontent=NewFileStream (Filepath,filemode.open); Filebyte=Newbyte[filecontent. Length]; Filecontent. Read (Filebyte,0, Filebyte. Length); Filecontent. Close (); } } stringEncodedfilename =Httputility.urlencode (name); WebOperationContext.Current.OutgoingResponse.ContentType="Application/octet-stream"; WEBOPERATIONCONTEXT.CURRENT.OUTGOINGRESPONSE.HEADERS.ADD ("content-disposition",string. Format ("attachment;filename=\ "{0}\"; Filename*=utf-8 ' {1}", Encodedfilename, Encodedfilename)); return NewMemoryStream (Filebyte);
Previous section code:
<button ng-click= "Imagedownload (item)" > Downloads </button>
this. downloadaccessory=function (fileId) { location.href=hostaddress+'mapscheme/ Imagedownload?name='+name; };
Effect:
Angular call the WCF service, read the folder slice display list, download Save as Picture