在c#.net中返回0字节[]
问题描述:
您好,.朋友,我在c#.net Web应用程序代码中使用以下方法来获取图像的字节
Hi.. Friends, I have the following method in my c#.net web application code to get bytes of the images
public byte[] pstFile(HttpPostedFile hf)
{
Stream fs = default(Stream);
byte[] bytes1 = null;
byte[] postfile = null;
fs = hf.InputStream;
BinaryReader a = new BinaryReader(hf.InputStream);
BinaryReader br1 = new BinaryReader(fs);
bytes1 = a.ReadBytes(hf.ContentLength);
postfile = bytes1;
return postfile;
}
但是,问题在于它返回了0个字节,而当我在另一个应用程序中编写相同的代码时,它就可以正常工作.
所以,请告诉我我哪里错了.
谢谢&问候
Parveen Rathi
but, the problem is that it return the 0 bytes and while I write the same code in another application it is working fine.
So, please tell me where I am wrong.
Thanks & regards
Parveen Rathi
答
您确实意识到大部分代码完全没有用,不是吗?您唯一有效的代码是:
You do realize that the majority of your code is completely useless, don''t you? The only effective code you have there is:
public byte[] pstFile(HttpPostedFile hf)
{
BinaryReader a = new BinaryReader(hf.InputStream);
return a.ReadBytes(hf.ContentLength);
}
因此,我怀疑如果它在其他应用程序中有效,那是因为它与您向我们展示的代码不同……
So I suspect that if this worked in a different application, it was because it wasn''t anything like the code you are showing us...