从Windows网络位置的fopen文件 [英] fopen file from windows network location

查看:167
本文介绍了从Windows网络位置的fopen文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以从安装网络驱动器从打开的文件,但不能卸载的1 \\\\例如mycomp \\文件夹2 \\ hi.bmp

I can open files from a mounted network drive, but not from an unmounted one e.g \\mycomp\folder2\hi.bmp

任何工作围绕这个?

推荐答案

下面的代码片段对我的作品:

The following snippet works for me:

char buffer[1000];    
FILE* file;
size_t bytesRead;

file = fopen("\\\\server\\share\\test.dat", "rb");  
if (file != NULL)
{
    bytesRead = fread(buffer, sizeof(char), sizeof(buffer), file);
    fclose(file);
}

另外要注意从文档的fopen(MSDN)此摘录:

...

的fopen会接受的路径
  在该点的文件系统上的有效
  执行; UNC路径和路径
  涉及映射的网络驱动器
  和fopen接受只要
  系统执行code的访问
  的共享或映射网络驱动器
  在执行的时间
。特别注意
  构建路径时,必须采取
  为FOPEN避免作出假设
  有关可用的驱动器,路径或
  网络共享在执行
  环境。结果
   ...

fopen will accept paths that are valid on the file system at the point of execution; UNC paths and paths involving mapped network drives are accepted by fopen as long as the system executing the code has access to the share or mapped network drive at the time of execution. Special care must be taken when constructing paths for fopen to avoid making assumptions about available drives, paths or network shares in the execution environment.
...

您还需要考虑,你是下运行您的程序的帐户,就需要有相应的存取权限的文件。当你上的共享为网络驱动器,也许你正在使用不同的凭据进行连接。这可能会导致的fopen 失败。

You also need to consider, that the account you are running your program under, needs to have the appropriate access rigths to the file. When you mount the share as a network drive, maybe you are using different credentials to connect. That could cause fopen to fail.

这篇关于从Windows网络位置的fopen文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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