介绍
这篇文章给大家介绍使用c#怎么保存上传的图片,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
[HttpPost], public string  UploadImage (), {,//string ss =, Request.Form [“uploadFile"];,//return 学生, HttpPostedFileBase uploadFile =, Request.Files [0];, string fileName =时间uploadFile.FileName;大敌;; int fileSize =时间uploadFile.ContentLength;大敌;; string fileExt =, Path.GetExtension(文件名).ToLower (),, string message =,““, if (! (==fileExt “.png", | |, fileExt ==,“.gif", | |, fileExt ==,“.jpg", | |, fileExt ==,“.jpeg")), {, 时间=message “图片类型只能为gif, png, jpg, jpeg",, return 消息, }, else {, if (fileSize 祝辞,(int) (500, *, 1024)), {, 时间=message “图片大小不能超过500 kb",, return 消息, }, else {, Random r =, new 随机(),, string uploadFileName =, DateTime.Now.ToString (“yyyyMMddhhmmss"), +, r.Next (100000,, 999999), +, fileExt;, try {, string directoryPath =, Server.MapPath (“~/UploadImages/?,, if (! Directory.Exists (directoryPath))//不存在这个文件夹就创建这个文件夹, {, Directory.CreateDirectory (Server.MapPath (“~/UploadImages/?),, }, uploadFile.SaveAs (Server.MapPath (“~/UploadImages/?, +, uploadFileName),, 时间=message uploadFileName;, return 消息, }, catch (Exception 交货), {, 时间=message ex.Message;, return 消息, }, }, } }
关于使用c#怎么保存上传的图片就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看的到。