Example #1
0
        public static string CreateFromK2Xml(string fileK2XML, string folderPath, string fileExtention)
        {
            string fileShortName = "";
            string fileFullname  = "";
            string fileContent   = "";

            fileExtention = fileExtention.Replace(".", "");
            folderPath    = Sugar.NormalizeFolderPath(folderPath);

            var dataSet = Sugar.GetDataSetFromXML(fileK2XML);

            fileShortName = (dataSet.Tables[0].Rows[0]["name"] ?? "").ToString();
            fileContent   = (dataSet.Tables[0].Rows[0]["content"] ?? "").ToString();

            if (GetExtention(fileShortName) != fileExtention)
            {
                throw new System.Exception("Создание файла из К2 XML. Расширение файла должно быть ." + fileExtention + System.Environment.NewLine);
            }

            fileFullname = folderPath + fileShortName;

            try
            {
                DeleteIfExists(fileFullname);


                System.IO.File.WriteAllBytes(fileFullname, System.Convert.FromBase64String(fileContent));
            }
            catch (System.Exception ex)
            {
                ex.Message = "Создание файла из К2 XML. Не удалось сохранить файл: " + fileFullname + ", причина: " + ex.Message + System.Environment.NewLine;
            }


            if (!System.IO.File.Exists(fileFullname))
            {
                throw new System.Exception("Создание файла из К2 XML. Файл не найден: " + fileFullname + System.Environment.NewLine);
            }


            return(fileShortName);
        }