asp.net不支持给定路径的格式 [英] the given path's format is not supported in asp.net

查看:214
本文介绍了asp.net不支持给定路径的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用流式代码.此代码由localhost.am成功运行,将我的网站托管到我的网站.

asp.net不支持给定路径的格式.

Am using flowing Code.this Code sucessfully running by localhost.am host my web this one Not working.getting Fllowing error.

the given path''s format is not supported in asp.net.

string date = DateTime.Now.ToShortDateString();
string newdate = date.Replace("/", ".");
string FileName = "" + newdate + ".TXT";
string filePath = @"C:/OUTBOUND/" + newdate + ".TXT";

Button Btngenarate0 = (Button)sender;

string strFilename = ((Button)sender).CommandArgument;
string strURL = Server.MapPath(@"~/C:/OUTBOUND/" + FileName + "");
WebClient req = new WebClient();
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.ClearContent();
response.ClearHeaders();
response.Buffer = true;
response.AddHeader("Content-Disposition", "attachment;filename=\"" + FileName + "\"");

byte[] data = req.DownloadData(Server.MapPath("~/C:/OUTBOUND/" + FileName + ""));
response.BinaryWrite(data);
response.End();

推荐答案

您为什么希望它能起作用?
Why would you expect that to work?
string strURL = Server.MapPath(@"~/C:/OUTBOUND/" + FileName + "");


这要求到您的网站根目录〜"的相对路径,后跟绝对磁盘引用.就像在说:


That requests a relative path to the root of your website "~" followed by an absolute disk reference. That''s like saying:

C:\My Documents\C:\Program Files

作为路径,它没有任何意义.

对于网站,您通常根本不会尝试指定绝对路径:因为您的网站的存储位置由IIS/托管服务管理员决定.尝试相对路径:

As a path, it doesn''t make any sense.

For a website, you would not normally try to specify an absolute path at all: because where your site is stored is at the discretion of IIS / the hosting service administrator. Try just the relative path:

string strURL = Server.MapPath(@"~/OUTBOUND/" + FileName + "");

应该可以.




使用此服务器位置

在应用程序服务器上设置文件夹路径.

字符串形式的Dim路径= Server.MapPath(〜/UploadedFiles//"&"\"&IO.Path.GetFileName(exlFileName.Replace("/",").Replace(:",")))


use this server location

set the folder path on application server.

Dim path As String = Server.MapPath("~/UploadedFiles//" & "\" & IO.Path.GetFileName(exlFileName.Replace("/", "").Replace(":", "")))


这篇关于asp.net不支持给定路径的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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