日期:2014-05-18  浏览次数:20439 次

图片经过BASE 64转码保存到服务器问题

现在有一段BASE64代码.原型是一张图片.

如何用.NET2.0 进行操作.

将这段代码进行解码,并上传到服务器的/image目录里面??


------解决方案--------------------
很简单的啊
System.IO.File.WriteAllBytes(Server.MapPath("~/image/xx.jpg"),Convert.FromBase64String("base64格式"))

例子
C# code
<%@ Page Language="C#" AutoEventWireup="true" ValidateRequest="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  protected void Button1_Click(object sender, EventArgs e)
  {
    System.IO.File.WriteAllBytes(Server.MapPath("~/images/xx.gif"), Convert.FromBase64String(Request.Form["content"]));
    Response.Redirect("~/images/xx.gif");
  }

</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
  <title></title>
</head>
<body>
  <form id="formd1" runat="server">
  <textarea name="content">R0lGODdhEAAQALMAAAAAAIAAAACAAICAAAAAgIAAgACAgMDAwICAgP8AAAD/AP//AAAA//8A/wD//////ywAAAAAEAAQAAAEOvDJSSt4K+u9r05gCGoel40kZqLpKb5ZySWm/NFc+cKLfv4LnC8IFKpwSKBnt+upTLUntPMAWK/YbAQAOw==</textarea>
  <asp:Button ID="Button1" runat="server" OnClientClick="getContent()" OnClick="Button1_Click"
    Text="服务器端的得到" />
  </form>
</body>
</html>