Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
When i run my website it show:"The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters."
And My View code:

ASP.NET
<%@ Page Title="register" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<blog.models.users>" %>
<%@ Import Namespace="blog.Models" %>
 <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<%using(Html.BeginForm("register","users",FormMethod.Post,new{enctype="multipart/form-data"}))
{%>  <br />
<input type="file" name="upic"/>
<input type="submit" value="upload"/>
<%}%>
   
</asp:Content>


the controller code is :
C#
[AcceptVerbs(HttpVerbs.Post)]
      public ActionResult register([Bind(Exclude = "file")]HttpPostedFileBase file, users u)
      {
              var v = db.users;
              var sna = Request.Form["name"];

              if (v.Count(d => d.name == sna) > 0)
              {

               ckn = 0;

              }

              if (ckn == 1 && sna !="")
              {
                  //如果没错误,返回首页

                  u.uid = SqlHelper.get_ID("users", "uid");
                  u.rdate = DateTime.Now;
                  u.ndate = DateTime.Now;
                  u.pwd = SqlHelper.md5(u.pwd);
                  u.jib = 2;
                  u.psum = 0;
                  file = Request.Files["upic"];
                    Int32 len = file.ContentLength;

                 u.pict = file.ContentType;


                 byte[] photo = new byte[len];

                 file.InputStream.Read(photo, 0, len);

                 u.upic = photo;




                  db.SubmitChanges();

                  db.users.InsertOnSubmit(u);
                  db.SubmitChanges();
              }
}

then, what may the error happen?and how to resolve this problem?
thx for helping me!
Posted
Updated 16-Mar-12 3:02am
v2
Comments
gavinv 17-Mar-12 10:27am    
someone say can do as below, but the error still happen, would somebody tell me why?
FileStream st = new FileStream(EmpPhoto,FileMode.Open,FileAccess.Read);
BinaryReader br = new BinaryReader(st, Encoding.UTF8);
System.Data.Linq.Binary b = new System.Data.Linq.Binary(br.ReadBytes(Convert.ToInt32(st.Length)));
st.Close();
gavinv 17-Mar-12 10:49am    
and also how to use like as this:

public static implicit operator Binary (byte[] value)

1 solution

please read this[^].
 
Share this answer
 
Comments
gavinv 17-Mar-12 8:28am    
Thank you for give me this link, but i post my controller code here is just to say that i'm not using EntityFrame,i just using linq to sql, so may i have another subjust? would somebody help me again?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900