cjJosephj
asked on
Path issue
Hi,
I'm trying to save a file outside my root folder.
so instead of http://myserver/rootfolder/file.csv I would like to save the file to
http://myserver/c://filefolder/file.csv.
i'm using c sharp and was thinking of doing something like servername + '?c=' + HttpContent.Response. but not sure if this is correct.
Thanks in advance
I'm trying to save a file outside my root folder.
so instead of http://myserver/rootfolder/file.csv I would like to save the file to
http://myserver/c://filefolder/file.csv.
i'm using c sharp and was thinking of doing something like servername + '?c=' + HttpContent.Response. but not sure if this is correct.
Thanks in advance
ASKER
Thanks for your reply.
I'm already using this to create the file
string Path = "C:" + "/" + filePath + fileName;
using (StreamWriter sw = File.CreateText(Path))
{
sw.Write(contents);
sw.Close();
}
But I also need to achieve something like
http://servername/c:/folder/file.csv
which i will create using
result.LoadXml("<root>" +
"<Url>" + servername + '?c=' + filePath + fileName + "</Url>" + <--- not sure how to achive this line
"</root>");
}
return result;
the reason for this is I need to create a csv file outside the root and then open the csv file in my browser so i need the http to direct me to the file once it has been created on the C: drive.
Sorry for the confusion.
I'm already using this to create the file
string Path = "C:" + "/" + filePath + fileName;
using (StreamWriter sw = File.CreateText(Path))
{
sw.Write(contents);
sw.Close();
}
But I also need to achieve something like
http://servername/c:/folder/file.csv
which i will create using
result.LoadXml("<root>" +
"<Url>" + servername + '?c=' + filePath + fileName + "</Url>" + <--- not sure how to achive this line
"</root>");
}
return result;
the reason for this is I need to create a csv file outside the root and then open the csv file in my browser so i need the http to direct me to the file once it has been created on the C: drive.
Sorry for the confusion.
Ok! Now I understand what do you need, you need to setup a virtual directory in your IIS that point to the folder that contains yours csv files, you know what I meant? I'm from my cellphone right now, I will go to my pc to make you an example.
ASKER
Thanks yu989c,
I have already created a virtual directory which contains my code. I would prefer to create the files on the c drive on the same server as at the moment the get created in the same folder as the folder that contains my code.
http://myserver/rootfolder(virtual directory)/file.csv
but this is what I would like.
http://myserver/c://filefolder(folder on the c drive)/file.csv. <---- is this possible?
Thank you so much for your help so far.
I have already created a virtual directory which contains my code. I would prefer to create the files on the c drive on the same server as at the moment the get created in the same folder as the folder that contains my code.
http://myserver/rootfolder(virtual directory)/file.csv
but this is what I would like.
http://myserver/c://filefolder(folder on the c drive)/file.csv. <---- is this possible?
Thank you so much for your help so far.
ASKER
Hi yu989c,
Please ignore my comment above and i will wait for your example.
Thanks
Please ignore my comment above and i will wait for your example.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you, I’m almost there
I created the virtual directory but for some reason it does not create my file when I use the snippet below
using (StreamWriter sw = File.CreateText(Server.Map Path("~") + "/" + filePath + fileName))
{
sw.Write(contents);
sw.Close();
}
This part works fine now
"<Url>" + servername + filePath + fileName + "</csv>" +
Thanks again
I created the virtual directory but for some reason it does not create my file when I use the snippet below
using (StreamWriter sw = File.CreateText(Server.Map
{
sw.Write(contents);
sw.Close();
}
This part works fine now
"<Url>" + servername + filePath + fileName + "</csv>" +
Thanks again
Hi buddy, if your file is outside of the application directory you dont need to make use of Server.MapPath("~") , try with this:
By using the method System.IO.File.WriteAllTex t you dont need to use the StreamWriter implementation, just one line :)
System.IO.File.WriteAllText(System.IO.Path.Combine(filePath, fileName), contents);
Please notice that filePath must be something like "C:\MyFolder\" and fileName something like "MyFile.csv"By using the method System.IO.File.WriteAllTex
ASKER
Thank you yu989c :)
Glad to help!
This code will create a file inside the application path:
C#
Open in new window
VBOpen in new window
This will create your file outside your root folder (C:\MyFolder):
C#
Open in new window
VBOpen in new window
Maybe I misunderstood your question...