上传文件问题,请问如何能只上传前10个字节到一个数组!

tavor 2004-01-11 10:23:33
上传文件问题,请问如何能只上传前10个字节到一个数组!

好像文件上传的时候不能只选几个字节上传是吧,可是整个上传的时侯,会提示有非法字符呢,我估计是文件内容的原因,不知道对不?

我用的方法如下,还是把整个文件作为一个文件输入流!
for(int i=0;i<20;i++)
{
this.dd.PostedFile.InputStream.Position=this.dd.PostedFile.InputStream.Position+1;
s[i]=(byte)this.dd .PostedFile .InputStream.ReadByte();
}
dd是 webservice对象
数组s为存放读取字节的数组

在另一个函数中
public string HelloWorld2(byte [] ss)
{
string s="";
try
{
for(int i=0;i<ss.Length;i++)
{
s=s+((char)ss[i]).ToString();
}
}
catch(Exception){return "there is a fault!";}
return s;
}

但是有时会出问题,就像我上面说的,还请高手指点一下
...全文
61 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
tavor 2004-01-29
  • 打赏
  • 举报
回复
yeah,I know your meaning.but i don't read bytes closely,i read one,then skip some bytes,read another byte.like this!
and as you said,before you use the HelloWorld2(byte [] ss),you still need to the whole input stream ,it means you still need to read the whole file! right?

but thank you all the same!
saucer 2004-01-11
  • 打赏
  • 举报
回复
after ReadByte, the position is moved too, so you don't need to move the Position manuall, try

int n = File1.PostedFile.ContentLength;
if (n>10)
n = 10;

byte[] bs = new byte[n];
File1.PostedFile.InputStream.Read(bs,0,n);

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧