Click here to Skip to main content
15,886,774 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
C#
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();
Posted
Updated 7-Dec-14 22:45pm
v2
Comments
Kornfeld Eliyahu Peter 8-Dec-14 4:45am    
Check the value of this: Server.MapPath("~/C:/OUTBOUND/"
syed shanu 8-Dec-14 4:46am    
Is there a c:/ in your server.
Do you have folder name C:/OUTBOUND in your server.
Might be this line string strURL = Server.MapPath(@"~/C:/OUTBOUND/" + FileName + "");

seems to be wrong.
[no name] 8-Dec-14 4:52am    
I allready Create OUTBOUND Floder in my server C drive.

Why would you expect that to work?
C#
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
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:
C#
string strURL = Server.MapPath(@"~/OUTBOUND/" + FileName + "");
That should work.
 
Share this answer
 
hi,

use this server location

set the folder path on application server.

Dim path As String = Server.MapPath("~/UploadedFiles//" & "\" & IO.Path.GetFileName(exlFileName.Replace("/", "").Replace(":", "")))
 
Share this answer
 
Comments
[no name] 8-Dec-14 5:40am    
only Working LocalHost Dear.
mudgilsks 8-Dec-14 5:47am    
you have to give the path of folder on server in which you upload file.
[no name] 8-Dec-14 6:11am    
I allready give path my Floder.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900