Click here to Skip to main content
15,907,492 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
System.IO.File.WriteAllText() not working in live host website.
Working code in local:
C#
DataTable dt = ds.Tables[0];
dt.TableName ="event";
string XMLDT = PLWM.Utils.CnvDataTableToXml(dt, false);         
System.IO.File.WriteAllText(@"D:\Works\TrueCallWEB\TrueCallWeb\Calendar-Monthly\events.xml", XMLDT);


but in live actual path is http://trucall.in/Calendar-Monthly/events.xml

i wrote code as
C#
System.IO.File.WriteAllText(@"Calendar-Monthly/events.xml", XMLDT); 

but its not working

What I have tried:

System.IO.File.WriteAllText(@"Calendar-Monthly/events.xml", XMLDT);
Posted
Updated 25-Feb-16 1:10am
v2
Comments
Member 11220730 25-Feb-16 7:08am    
have any problem in path?
F-ES Sitecore 25-Feb-16 7:16am    
In addition to it possibly being permissions, if you want to write to a file inside your web space you should use MapPath to work out what the physical path should be;

Server.MapPath("~/yourfolder/yourfile.txt")

1 solution

What do you mean it is not working? You'll get an error. I'm going to guess the error is a permissions issue. Most hosters will not by default set your app up so that it has permissions to write to their file system.

You'll have to contact them directly and ask for some space to store files on.
 
Share this answer
 
Comments
Member 11220730 25-Feb-16 7:17am    
events.xml file is my own no need of permissions
ZurdoDev 25-Feb-16 7:32am    
Of course you need permissions. You said you are trying to write a file to your hoster's server.
Member 11220730 25-Feb-16 7:34am    
For permissions what i have to do.
ZurdoDev 25-Feb-16 7:44am    
Ask your hoster.

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