File reading and writing in c# -


my code is

        try         {             string mtellthemepath = configurationmanager.appsettings["mtellthemepath"] == null ? server.mappath("~/app_themes/") : configurationmanager.appsettings["mtellthemepath"].contains("%%") ? server.mappath("~/app_themes") : configurationmanager.appsettings["mtellthemepath"];              string[] folderpaths = directory.getdirectories(mtellthemepath);             string currentsurveythemename = hfsurveyname.value + "_" + hfclientid.value;             string clonesurveythemename = lstsurvey[0].surveyname + "_" + identity.current.userdata.clientid;             string clonesurveythemepath = mtellthemepath + "\\" + lstsurvey[0].surveyname + "_" + identity.current.userdata.clientid;              string cssfile = clonesurveythemepath + "\\" + clonesurveythemename + ".css";             string skinfile = clonesurveythemepath + "\\" + clonesurveythemename + ".skin";              string filecontentcss = string.empty;             string filecontentskin = string.empty;              foreach (string ofolder in folderpaths)             {                 if (ofolder.split('\\')[5] == currentsurveythemename)                 {                     string[] cssskinfiles = directory.getfiles(ofolder);                     foreach (string objfile in cssskinfiles)                     {                         if (objfile.split('\\')[6].split('.')[1] == "css")                         {                             filecontentcss = file.readalltext(objfile);                         }                         if (objfile.split('\\')[6].split('.')[1] == "skin")                         {                             filecontentskin = file.readalltext(objfile);                         }                     }                 }             }             directory.createdirectory(clonesurveythemepath);             file.create(cssfile);             file.create(skinfile);             if (filecontentcss != string.empty)             {                 file.writealltext(cssfile, filecontentcss);             }             if (filecontentskin != string.empty)             {                 file.writealltext(skinfile, filecontentskin);             }             return lstsurvey[0].surveyguid;         }         catch (exception ex)         {             throw ex;         } 

it giving error as:

the process cannot access file 'd:\projects\mtelligence\mtelligence.web\app_themes\clone_forclonetest_-1\clone_forclonetest_-1.css' because being used process.

please me .......... how solve this

iam trying read .css,.skin files folder , write same files in folder different name

look this:

file.create(cssfile); file.create(skinfile); if (filecontentcss != string.empty) {     file.writealltext(cssfile, filecontentcss);     // ... } 

actually file.create dos not create file creates file , returns open stream it. subsequent call file.writealltext try write file open yourself. in case (because not use streams returned file.create) remove them:

if (filecontentcss != string.empty) {     file.writealltext(cssfile, filecontentcss);     // ... } 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -