Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Using umbraco version 8
I need to store a string entered by user to a file. I needs to be stored in a set location from the root directory.
Can someone please point me in the correct direction.
Hi Daniel,
Use this method server side:
public string WriteToFile(string filePath, string data) { try { try { if (File.Exists(filePath)) { File.Delete(filePath); } } catch (Exception ignore) { } File.AppendAllText(filePath, data); return "success"; } catch (Exception ex) { return ex.Message; } }
Also, in case you need it, use this to get the root and folder path of your app:
System.Web.Hosting.HostingEnvironment.MapPath("~/YouFolderPath")
Solved: Thanks Graham. Had to modify things slightly and here is the code and it works great.
public string WriteToFile(string filePath, string data) { var file = new FileInfo(filePath); try { try { if (file.Exists) { file.Delete(); } } catch (Exception ignore) { } try { FileStream fs = file.Create(); StreamWriter w = new StreamWriter(fs); w.Write(data); w.Close(); fs.Close(); } catch (Exception ignore) { } return "success"; } catch (Exception ex) { return ex.Message; } }
You're Welcome! Can I get a High 5?
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Store a text file
Using umbraco version 8
I need to store a string entered by user to a file. I needs to be stored in a set location from the root directory.
Can someone please point me in the correct direction.
Hi Daniel,
Use this method server side:
Also, in case you need it, use this to get the root and folder path of your app:
System.Web.Hosting.HostingEnvironment.MapPath("~/YouFolderPath")
Solved: Thanks Graham. Had to modify things slightly and here is the code and it works great.
You're Welcome! Can I get a High 5?
is working on a reply...