| 发表于:2007-07-10 17:14:17 楼主 |
代码 system.drawing.image img = system.drawing.image.fromfile(fileinfo); system.io.memorystream ms = new system.io.memorystream(); //取得文件的扩展名,保存文件格式 int j=fileinfo.lastindexof( "\\ "); int i=fileinfo.lastindexof( ". "); string filename=fileinfo.substring(j+1,i-j); string extname=fileinfo.substring(i+1); switch(extname.toupper()) { case "gif ": img.save(ms, system.drawing.imaging.imageformat.gif); break; default : img.save(ms,system.drawing.imaging.imageformat.jpeg); break; } string newname=datetime.now.year.tostring()+datetime.now.month.tostring()+datetime.now.day.tostring()+datetime.now.hour.tostring()+datetime.now.minute.tostring()+datetime.now.second.tostring(); byte[] by = ms.toarray(); string savepath = server.mappath( "images\\product "); filestream filestream = null; try { filestream = new filestream(savepath.replace( "\\ajax ", " ") + "c:\\ " + newname+ ". "+extname, filemode.create, fileaccess.write); //filestream = new filestream( "c:\\up\\ " + newname+ ". "+extname, filemode.create, fileaccess.write); //write the file filestream.write(by, 0, by.length); filestream.flush();//clear the buffer,write the data to the hard disk } catch(exception ex) { string s=ex.tostring(); throw; } finally { filestream.close(); } |
|
|
|
|