3

ファイル アップロード コントロールがあり、ファイル コンテンツを読み取る必要があります。

実際のファイルの内容は

CREATE PROCEDURE dbo.ws_Device_Update
(
    @ApplicationId uniqueidentifier   ,
    @OriginalApplicationId uniqueidentifier   ,
    @DeviceIMEI nvarchar (50)  ,
    @OriginalDeviceIMEI nvarchar (50)  ,
    @ModelId int   ,
    @DeviceName nvarchar (50)  ,
    @DeviceDescription nvarchar (255)  ,
    @DeviceState int   ,
    @IsExpired bit   ,
    @IsSuspended bit   ,
    @LastAccessed datetime   ,
    @ClientSeqNo bigint   ,
    @ServerSeqNo bigint   ,
    @ModelCode varchar (50)  ,
    @PushToken varchar (512)  ,
    @PushLastAlive datetime   ,
    @PushLastDead datetime   ,
    @DeviceType int   
)
AS

そして、私は以下のプログラムを使用しています

int fileLength = fileUpload.PostedFile.ContentLength;            
Byte[] contentInBytes = new Byte[fileLength];
using (Stream streamContent = fileUpload.FileContent)
{
  streamContent.Read(contentInBytes, 0, fileLength);
}
var xx = ASCIIEncoding.ASCII.GetString(contentInBytes);

私が得ている出力は

???CREATE PROCEDURE dbo.ws_Device_Update
(
    @ApplicationId uniqueidentifier   ,
    @OriginalApplicationId uniqueidentifier   ,
    @DeviceIMEI nvarchar (50)  ,
    @OriginalDeviceIMEI nvarchar (50)  ,
    @ModelId int   ,
    @DeviceName nvarchar (50)  ,
    @DeviceDescription nvarchar (255)  ,
    @DeviceState int   ,
    @IsExpired bit   ,
    @IsSuspended bit   ,
    @LastAccessed datetime   ,
    @ClientSeqNo bigint   ,
    @ServerSeqNo bigint   ,
    @ModelCode varchar (50)  ,
    @PushToken varchar (512)  ,
    @PushLastAlive datetime   ,
    @PushLastDead datetime   ,
    @DeviceType int   
)
AS

いくつかの余分な??? キャラクターがやってくる...どこからかわからない?

生成されたバイト配列は

239,187,191,67,82,69,65,84,69,32,80,82,79,67,69,68,85,82,69,32,100,98,111,46,119,115,95,68,101,118,105,99,101,95, 85,112,100,97,116,101,13,10,40,13,10,9,64,65,112,112,108,105,99,97,116,105,111,110,73,100,32,117,110,105,113,117,               101,105,100,101,110,116,105,102,105,101,114,32,32,32,44,13,10,9,64,79,114,105,103,105,110,97,108,65,112,112,108,                105,99,97,116,105,111,110,73,100,32,117,110,105,113,117,101,105,100,101,110,116,105,102,105,101,114,32,32,32,44,                13,10,9,64,68,101,118,105,99,101,73,77,69,73,32,110,118,97,114,99,104,97,114,32,40,53,48,41,32,32,44,13,10,9,64,                79,114,105,103,105,110,97,108,68,101,118,105,99,101,73,77,69,73,32,110,118,97,114,99,104,97,114,32,40,53,48,41,32,                32,44,13,10,9,64,77,111,100,101,108,73,100,32,105,110,116,32,32,32,44,13,10,9,64,68,101,118,105,99,101,78,97,109,                101,32,110,118,97,114,99,104,97,114,32,40,53,48,41,32,32,44,13,10,9,64,68,101,118,105,99,101,68,101,115,99,114,105,                112,116,105,111,110,32,110,118,97,114,99,104,97,114,32,40,50,53,53,41,32,32,44,13,10,9,64,68,101,118,105,99,101,83,                116,97,116,101,32,105,110,116,32,32,32,44,13,10,9,64,73,115,69,120,112,105,114,101,100,32,98,105,116,32,32,32,44,13,                10,9,64,73,115,83,117,115,112,101,110,100,101,100,32,98,105,116,32,32,32,44,13,10,9,64,76,97,115,116,65,99,99,101,115,                115,101,100,32,100,97,116,101,116,105,109,101,32,32,32,44,13,10,9,64,67,108,105,101,110,116,83,101,113,78,111,32,98,105,                103,105,110,116,32,32,32,44,13,10,9,64,83,101,114,118,101,114,83,101,113,78,111,32,98,105,103,105,110,116,32,32,32,44,13,                10,9,64,77,111,100,101,108,67,111,100,101,32,118,97,114,99,104,97,114,32,40,53,48,41,32,32,44,13,10,9,64,80,117,115,104,84,                111,107,101,110,32,118,97,114,99,104,97,114,32,40,53,49,50,41,32,32,44,13,10,9,64,80,117,115,104,76,97,115,116,65,108,105,                118,101,32,100,97,116,101,116,105,109,101,32,32,32,44,13,10,9,64,80,117,115,104,76,97,115,116,68,101,97,100,32,100,97,116,                101,116,105,109,101,32,32,32,44,13,10,9,64,68,101,118,105,99,101,84,121,112,101,32,105,110,116,32,32,32,13,10,41,13,10,65,83

「239,187,191」がどこから来たのかわかりません...これを解決する方法の手がかりはありますか?

ありがとう

4

2 に答える 2

4

239 187 191バイトオーダーマークを表すUTF-8

StreamReader Constructor (String, Encoding, Boolean)エンコーディングを検出するパラメータがあることを試してください

StreamReader reader = new StreamReader(fileUpload.FileContent, 
                  Encoding.Unicode, true);

string fromFile= reader.ReadToEnd();
于 2013-04-23T05:07:59.090 に答える
3

ユニコードのバイトオーダーマークです。
を使用しvar xx = Encoding.UTF8.GetString(contentInBytes);ます。

于 2013-04-23T05:00:33.300 に答える