0

Not sure what could cause this on an output file. File is created globally here:

    static string dt = DateTime.Today.ToString("MMddyyyy");

    static string filename = "CBI_" + dt + "_providers.json";
    static string filepath = Convert.ToString(ConfigurationManager.AppSettings["Outpath"]);

    System.IO.TextWriter writeFile = new StreamWriter(filepath + filename);

and written to here:

 writeFile.WriteLine(JsonConvert.SerializeObject(ListALL));

This works fine from my local machine but throws the exception on our application server, even after creating this file in specified path and with specified name but with 0 bytes.

bobmc
  • 11
  • 3
    Is `filepath + filename` a *valid* path? We cannot debug your code. Please provide us with enough information to understand what is happening. What does `filepath` contain? –  Nov 02 '18 at 14:17
  • 7
    use Path.Combine for creating paths – Joe Phillips Nov 02 '18 at 14:17
  • 2
    Sounds like a file security issue. Check the permissions of the folder and the user you are writing the file as. – JAZ Nov 02 '18 at 14:17
  • 4
    When dealing with file paths I reccomend to always use `Path.Combine(path, fileName)` [Path Class](https://learn.microsoft.com/en-us/dotnet/api/system.io.path?view=netframework-4.7.2) – Alfie Nov 02 '18 at 14:20
  • `AppSettings[]` returns a string already; there's no need for `Convert.ToString()`. – Heretic Monkey Nov 02 '18 at 14:20
  • Possible duplicate of [How to write a Json file in C#?](https://stackoverflow.com/questions/16921652/how-to-write-a-json-file-in-c) – Heretic Monkey Nov 02 '18 at 14:21
  • This could also be an issue with using a network path that cannot be mapped from the application server. Please provide us with additional information. –  Nov 02 '18 at 14:27
  • Id check for modify rights, sounds like you have create but not modify, – Trey Nov 02 '18 at 14:32
  • Added the Path.Combine but it did not resolve this. If this were a permissions issue or an issue with the network path why would it be able to create the 0 byte file? I am thinking it might be because the Json serializer can not be instantiated? What would need to be placed on the server for this ...anything? – bobmc Nov 02 '18 at 16:58

0 Answers0