在c#.net中返回0字节[] [英] Return 0 byte[] in c#.net

查看:80
本文介绍了在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...


这篇关于在c#.net中返回0字节[]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆