0
private void saveStudent<T>(string filePath, T objectToWrite) 
{
  stream = File.OpenWrite(filePath); **//Error is here**
  var binaryData = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
  binaryData.Serialize(stream, objectToWrite);
  stream.Close();
}
Obsidian Age
  • 41,205
  • 10
  • 48
  • 71
  • i'm new here so not sure how all this works. – Kenic Nickardo Apr 12 '18 at 04:02
  • What is the value of `filePath` and what platform is this running on? – S.C. Apr 12 '18 at 04:04
  • What is the value of `filePath`? – Ilian Apr 12 '18 at 04:04
  • Windows 10 string filePath = "DriveName:\\Folder\\FileName.Extension";@Ilian Pinzon – Kenic Nickardo Apr 12 '18 at 04:06
  • DriveName doesn't sound like a valid drive – Keith Nicholas Apr 12 '18 at 04:07
  • I call shenanigans, please read https://msdn.microsoft.com/en-us/library/system.io.file.openwrite(v=vs.110).aspx and then https://msdn.microsoft.com/en-us/library/y740d9d3.aspx – TheGeneral Apr 12 '18 at 04:08
  • Please don't use `BinaryFormatter`. – Ron Beyer Apr 12 '18 at 04:09
  • 1
    I'm voting to close this question as off-topic because there has been no attempt to debug this code and no attempt at reading the documentation. Additionally no attempt to put the relevant details in the question – TheGeneral Apr 12 '18 at 04:09
  • well just coding using what my teacher gave to me i tried C:\\ it didnt work @KeithNicholas – Kenic Nickardo Apr 12 '18 at 04:10
  • 3
    if you don't show us the EXACT string you are using we can't help it needs to be a valid file path – Keith Nicholas Apr 12 '18 at 04:11
  • it can't be C:\\ that's not a path to a file – Keith Nicholas Apr 12 '18 at 04:12
  • private void saveButton_Click(object sender, EventArgs e) { stud = new Student(); stud.setStudentID(studentIDTextBox.Text); stud.setFirstName(firstNameTextBox.Text); stud.setLastName(lastNameTextBox.Text); saveStudent(filePath, stud); MessageBox.Show("Saved"); } @KeithNicholas sorry im i dont know how put it in that fancy coding box – Kenic Nickardo Apr 12 '18 at 04:22
  • @SpicySensei, you need to help us help you. What is the absolute file path you're passing through? Chances are it's just an OS specific slash problem that would be simple as sin to fix, but we just need the info. – James Whyte Apr 12 '18 at 04:23
  • @JamesWhyte what do mean by absolute file path ? like where file is located ? – Kenic Nickardo Apr 12 '18 at 04:26
  • best solution to this problem is get better understanding of concepts before asking a question sorry for inconvenience i wasted your time when you could have help others sorry everyone – Kenic Nickardo Apr 12 '18 at 04:36

0 Answers0