Access denied while saving html file to my desktop

Viewed 34
    const string filename = "Report_design.html";

    string strPath = Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);

    var content = File.ReadAllText(filename);

    content = content.Replace("{Model}", model);

    File.WriteAllText(strPath, content);

Error pops up : System.UnauthorizedAccessException: 'Access to the path is denied' What am I trying to achieve is that I created a Report_design.html file to be save as a template and write a new Report_design.html to my desktop .Can anyone tell me how should I resolve this issues as I want to set the fix desktop where the file will be saved every time.

1 Answers
string save_report = strPath + "\\Report.html";

Simply add a new string as strPath + filename and format .The problem of my question is that you cannot WriteAllText with just the Desktop filepath but also need to include the filename and format in order to save to the desktop. Well everyone start from somewhere so I'm still learning and wanted to be very good in coding. Thanks ! Solved

Related