File.readallbytes()返回{byte [0]} [英] File.readallbytes() return {byte[0]}

查看:100
本文介绍了File.readallbytes()返回{byte [0]}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用asp.net webservice将文件提升到特定位置。当我写这篇文章时:



byte [] file = FileUpload1.FileBytes;

和传递webservice,webservice工作正常。客户端可以是Windows服务可能不是web应用程序。文件路径可以发送到service.From文件路径,我想转换为字节数组。所以我用过



byte [] array = File.ReadAllBytes(C:\\Users \\riya\\Desktop\\sample.txt);

但它不起作用.Array总是包含零{byte [0]}。如何处理这个?



我是什么尝试过:



byte [] array = File.ReadAllBytes(C:\\Users\\riya\\Desktop \\sample.txt);

I want to uplad file to specific location using asp.net webservice .When I writing this:

byte[] file = FileUpload1.FileBytes;
and passing webservice,webservice works fine.Client can be windows service may not web application.File path can be sent to service.From file path,I want to convert to byte array.So I used

byte[] array = File.ReadAllBytes("C:\\Users\\riya\\Desktop\\sample.txt");
But it is not working.Array always contain zero{byte[0]}.How to handle this?

What I have tried:

byte[] array = File.ReadAllBytes("C:\\Users\\riya\\Desktop\\sample.txt");

推荐答案

问题是服务不在您的用户ID下运行 - 它在没有'的系统用户下运行可以访问您的用户数据。由于该文件位于用户桌面上,因此该服务无权访问该文件。因此,ReadAllBytes调用将抛出异常并且您的代码可能正在捕获它并将其替换为空数组。

将文件移动到其他文件夹,并确保所有用户都可以访问它包含的文件。
The problem is that a Service doesn't run under your userID - it runs under a system user that doesn't have access to your user's data. And since that file is on a user's desktop, the service doesn't have any access to it. As a result, the ReadAllBytes call will throw an exception and your code is presumably catching that and replacing it with an empty array.
Move your file to a different folder, and ensure that all users have access to the files it contains.


这篇关于File.readallbytes()返回{byte [0]}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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