FileStream VoiceFile = new FileStream("D:\\Program Files\\RecordServer\\Database\\voiceFile\\" + a, FileMode.Open);                UAccessory uAccessorytemp = new UAccessory();
                uAccessorytemp.Size = VoiceFile.Length.ToString();
                uAccessorytemp.People.Code = ((UPeople)Session["LoginPeople"]).Code;
                uAccessorytemp.Time = DateTime.Now;
                uAccessorytemp.PrefixName = VoiceFile.Name.Substring(VoiceFile.Name.LastIndexOf("\\") + 1);
                uAccessorytemp.SuffixName = VoiceFile.Name.Substring(VoiceFile.Name.LastIndexOf(".") + 1);
我写到这里就不会了,实体uAccessorytemp.content是二进制的类型,我想把VoiceFile 这个文件转化成二进制,然后存进数据库里,应该怎么写,才能转化?

解决方案 »

  1.   

    FileStream对象本身就有提供一个read方法,可将文件流读取二进制中,你看一下就知道了嘛
      

  2.   


    FileStream fsFileRead = new FileStream( 
       FileName, 
       FileMode.Open, 
       FileAccess.Read); 
       
      byteDataValue = new byte[LINE_SIZE]; 
      charDataValue = new char[LINE_SIZE]; 
       
      string strLine = string.Empty; 
      int intLength = 0; 
       
      while (fsFileRead.Read(byteDataValue, 0, byteDataValue.Length) == byteDataValue.Length) 
      { 
       Encoding.Default.GetDecoder().GetChars(byteDataValue, 0, byteDataValue.Length, charDataValue, 0, true); 
       strLine = new string(charDataValue); 
       
       ... 
       ... 
       ... 
       
       intLength += LINE_SIZE; 
       fsFileRead.Seek(intLength, SeekOrigin.Begin); 
      }