附件上传到服务器后无法打开 [英] Attached files are not opening when uploaded to server

查看:154
本文介绍了附件上传到服务器后无法打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


在我的应用程序中,我正在使用文档上传.我将整个应用程序粘贴到服务器中,其中有一个名为Enclosure的文件夹.当我单击上载按钮时,文件将存储在该文件夹中.我有一个按钮可以打开该附件,它在本地系统中运行良好,但不适用于该服务器系统,也不会引发任何错误.谁能帮我解决这个问题.

这是我的显示"按钮代码;

Hi Everyone,


In my application I am using the document upload. I will paste my whole application in the server, there is the folder named as Enclosure. When I click the upload button the file will be stored in that folder.And i have one button to open that attached file it is working fine in local system, but it is not working for that server system it is not throwing any error. Can anyone help me to solve this problem.

Here is my Show button Code;

protected void btnenshow_Click(object sender, ImageClickEventArgs e)
   {
       string DirectoryPath = Server.MapPath("") + System.IO.Path.DirectorySeparatorChar + "Enclosure";

       docFileNameWithPath = DirectoryPath + "\\" + lstUpload.SelectedValue;
       string filename = lstUpload.SelectedValue;
       string str = "http://" + Request.Url.Authority + Request.ApplicationPath + "/Enclosure/" + filename;
       if (System.IO.File.Exists(docFileNameWithPath))
           Process.Start(str);


}


问候
Nanda


}


Regards
Nanda

推荐答案

正在开放.

它正在服务器上打开,与您在开发中对其进行测试时完全一样.问题是,当您对其进行测试时,服务器和客户端是同一台计算机.现在,客户端是一台机器,而服务器是另一台机器.在服务器上发出Process.Start时,应用程序在服务器而不是客户端上运行.

除非在非常特殊的情况下(不能在99%的情况下发生),否则无法从服务器上可靠地执行客户端上的应用程序.
It is opening.

It is opening on the Server, exactly as it did when you tested it in development. The trouble is, when you tested it, the Server and the Client were the same machine. Now, the client is one machine, and the server is another. When you issue Process.Start on the server, the application runs on the server, not the client.

You cannot reliably execute an application on the client from the server except under very specific circumstances which will not occur in 99% of situations.


尝试此代码.....

试试
{
字符串文件名= Path.GetFileName(FileUpload1.FileName);

FileUpload1.SaveAs(Server.MapPath(〜\\")+"\\ Request form \\" + TextBox4.Text +"_" +文件名);
Session ["val"] =〜\\请求表单\\" + TextBox4.Text +"_" +文件名;
Label4.Text =上传状态:文件已上传!";
}
catch(ex ex例外)
{
Label4.Text =上传状态:无法上传文件.发生以下错误:" + ex.Message;
}
Try this code.....

try
{
string filename = Path.GetFileName(FileUpload1.FileName);

FileUpload1.SaveAs(Server.MapPath("~\\") + "\\Request form\\" + TextBox4.Text + "_" + filename);
Session["val"] = "~\\Request form\\" + TextBox4.Text + "_" + filename;
Label4.Text = "Upload status: File uploaded!";
}
catch (Exception ex)
{
Label4.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
}




使用Response.Redirect.

传递FileName及其路径以下载/查看.

其他方法可以在下面找到(使用System.Diagnostics.Process)
http://support.microsoft.com/kb/555134 [
Hi,

Use Response.Redirect.

Pass the FileName with its path to download / view.

The Other method ca be found below (Using System.Diagnostics.Process)
http://support.microsoft.com/kb/555134[^]

Regards,
Raghu


这篇关于附件上传到服务器后无法打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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