Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

FLAT file creation

$
0
0

Hi,

I want to create a .txt file at the time of Sharepoint feature activation. I am able to create that file using this code

string fullFilePath = string.Format("{0}{1}", filePath, fileNmae);
            if (!System.IO.File.Exists(fullFilePath))
            {
                FileStream fs = File.Create(string.Format("{0}{1}", filePath, string.Format(fileNmae)));
                fs.Close();
            }

But Whenever I am trying to open and write something into that file,its giving an error "file is being used by another process".

f (System.IO.File.Exists(fullFilePath))
            {
                using (FileStream fileStream = File.OpenRead(fullFilePath))
                {
                    File.WriteAllText(string.Format("{0}{1}", filePath, fileNmae), string.Join("{0}\n{1}\n{2}\n{3}", DateTime.Now.ToString(), msg, stackTrace, "xxxx"));
                }
            }
Can you please tell me where I am wrong.


Shubho


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>