Dev2.Diagnostics.DebugItem.SaveFile C# (CSharp) Method

SaveFile() public method

public SaveFile ( string contents, string fileName ) : string
contents string
fileName string
return string
        public virtual string SaveFile(string contents, string fileName)
        {

            if(string.IsNullOrEmpty(contents))
            {
                throw new ArgumentNullException("contents");
            }
            contents = TextUtils.ReplaceWorkflowNewLinesWithEnvironmentNewLines(contents);
            fileName = InvalidFileNameChars.Aggregate(fileName, (current, c) => current.Replace(c.ToString(CultureInfo.InvariantCulture), ""));

            var path = Path.Combine(_tempPath, fileName);
            File.AppendAllText(path, contents);
            string linkUri = string.Format(EnvironmentVariables.WebServerUri + "/Services/{0}?DebugItemFilePath={1}", "FetchDebugItemFileService", path);

            return linkUri;
        }

Usage Example

        // ReSharper disable InconsistentNaming - Unit Test
        public void SaveFile_With_Contents_Expected_SavesFileToDisk()
        // ReSharper restore InconsistentNaming
        {
            var debugState = new DebugItem();

            debugState.ClearFile("TestFile.txt");
            EnvironmentVariables.WebServerUri = "http://localhost:3142";
            var uri = debugState.SaveFile(LongText, "TestFile.txt");
            var path = new Uri(uri).OriginalString.Replace("?DebugItemFilePath=", "").Replace(EnvironmentVariables.WebServerUri + "/Services/FetchDebugItemFileService", "");
            var exists = File.Exists(path);
            Assert.IsTrue(exists);

            var contents = File.ReadAllText(path);
            Assert.AreEqual(LongText, contents);
        }
All Usage Examples Of Dev2.Diagnostics.DebugItem::SaveFile