如何从网络驱动器检索或查看图像? [英] How to retrieve or view image from network drive?

查看:71
本文介绍了如何从网络驱动器检索或查看图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我在网络驱动器上成功上传了图片,但现在我无法从同一条路径查看该图片请帮助我。

当我在应用程序中保存图像时只需给出视图按钮的路径: - '.. / Images / Emp Docs /<%#Eval(Salary_URL)%>'它正常工作,但我可以为网络驱动做什么。





这是上传代码:

protected void btnUpLoad_Click(object sender,EventArgs e)

{

mydt =(DataTable)(ViewState [mydatatable]);

// DataRow myrow = mydt.NewRow();

DataRow myrow = mydt .NewRow();



string filePath = Path.Combine(Z:\\,Emp Docs);



//也尝试下面适用于本地驱动器,但在映射网络驱动器上失败

//字符串filePath = Path.Combine(Environment.CurrentDirectory,@。 .\\..\\dev\\WebRootFolder \\SourceFolder \\ImageFolder);



HttpFileCollection uploadedFiles = Request.Files;



for(int i = 0;我< uploadedFiles.Count; i ++)

{

HttpPostedFile userPostedFile = uploadedFiles [i];



尝试

{

if(userPostedFile.ContentLength> 0)

{

//UploadLabel.Text + =文件# +(i + 1)+

//

;



UploadLabel.Text + = userPostedFile .FileName;





userPostedFile.SaveAs(filePath +\\+

路径。 GetFileName(userPostedFile.FileName));



UploadLabel1.Text + = filePath +\\+

Path.GetFileName( userPostedFile.FileName);

}

}

catch(Exception Ex)

{

UploadLabel.Text + =错误:
+ Ex.Message;

}

}

Hi to all i am successfully uploaded image in network drive but now i unable to view that image from the same path please help me.
when i am save image in application only then just give the path for view button:-'../Images/Emp Docs/<%#Eval("Salary_URL")%>' it is working but whta can i do for network drive.


this is upload Code:
protected void btnUpLoad_Click(object sender, EventArgs e)
{
mydt = (DataTable)(ViewState["mydatatable"]);
//DataRow myrow = mydt.NewRow();
DataRow myrow = mydt.NewRow();

string filePath = Path.Combine("Z:\\", "Emp Docs");

//also tried below which works on local drive, but failed on mapped network drive
//string filePath = Path.Combine(Environment.CurrentDirectory, @"..\\..\\dev\\WebRootFolder\\SourceFolder\\ImageFolder");

HttpFileCollection uploadedFiles = Request.Files;

for (int i = 0; i < uploadedFiles.Count; i++)
{
HttpPostedFile userPostedFile = uploadedFiles[i];

try
{
if (userPostedFile.ContentLength > 0)
{
//UploadLabel.Text += "File #" + (i + 1) +
// "

";

UploadLabel.Text += userPostedFile.FileName;


userPostedFile.SaveAs(filePath + "\\" +
Path.GetFileName(userPostedFile.FileName));

UploadLabel1.Text += filePath + "\\" +
Path.GetFileName(userPostedFile.FileName);
}
}
catch (Exception Ex)
{
UploadLabel.Text += "Error:
" + Ex.Message;
}
}

推荐答案

您的第一种方法依赖于映射的驱动器配置。映射驱动器仅与当前用户相关,因此当您可能看到z:时,您的Web应用程序应该在专用安全帐户下运行时没有理由使用此映射。



您的第二种方法仅适用于本地驱动器。您正在尝试获取从当前路径派生的路径。这不会拉入网络路径。



您需要做的是使用文件夹的UNC路径。如果查看z驱动器的映射,您将看到物理路径是什么。这必须成为你道路的一部分。



我提到你的网络应用程序应该在一个单独的帐户中运行。您必须将访问UNC文件夹的权限分配给帐户,否则它将无法看到它。您的系统管理员必须为您执行此操作。
Your first approach relies on a mapped drive configuration. A mapped drive is relevant only to the current user, so while you might be able to see z:, there's no reason that your web application which should be running under a dedicated secure account will have this mapping.

Your second approach only works on the local drive. You are trying to get the path that is derived from your current path. This will not pull in a network path.

What you need to do is use the UNC path to the folder. If you look at the mapping for your z drive, you will see what the physical path is. That must form part of your path.

I mentioned that your web application should be running in a separate account. You will have to assign the rights to access your UNC folder to the account otherwise it's not going to be able to see it. Your system administrators will have to do this for you.


这篇关于如何从网络驱动器检索或查看图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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