Sharing violation during save as on Ubuntu Linux

0 votes

I'm new to C# and I'm having a bit of an issue when saving to a new file. My program has two options for saving: save & save as.

I was getting a sharing violation error when saving, but I fixed that by closing the previous filestream. However, I still cant figure out why my save as code is giving me a sharing violation error.

Here's the code:

        // get a file stream from the file chooser
        FileStream file = File.OpenWrite(saveFc.Filename);
        // check to see if the file is Ok
        bool fileOk = file.CanWrite;
        if (fileOk == true)
        {
            // get the filename
            string filename = file.Name;
            // store the filename for later use
            UtilityClass.filename = filename;
            // get the text from textview1
            string text = textview1.Buffer.Text;
            // get a StreamWriter
            StreamWriter writer = File.CreateText(filename);
            // write to the file
            writer.Write(text);
            // close/save the file
            writer.Close();
            file.Close();
        }
    }
    // close the file c

If you could help me figure it out that would be much appreciated. Thanks!

May 10, 2022 in Linux Administration by Edureka
• 13,690 points

edited 4 days ago 86 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP