I'm trying to upload a .srt file through an API that takes File as a parameter.
The file is stored on the server, and I'm using
StreamWriter to write to it:
string path = Server.MapPath("~/App_Data/captions/" + entryId) + ".srt"; FileStream f = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite); StreamWriter s = new StreamWriter(f); s.Write(someString); f.Flush() // Connecting to API and uploading the file s.Close();
However, even though the file is created correctly on my server, the uploaded file is empty. If the file already exists, it will upload that file correctly but only contain the existing content, and not the additional text I added from
f.Flush() would ensure that the data in StreamWriter is written and saved to the file, but that doesn't seem to be the case.
What do I have to do to make sure that the data is written to the file before it is uploaded through the API?