Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public static string FindByFirstNamePart(string firstNamePart, string fileExtention, string folderPath)
        {
            folderPath = Sugar.NormalizeFolderPath(folderPath);

            if (fileExtention != "" && System.IO.Directory.Exists(folderPath))
            {
                string[] fileNames = System.IO.Directory.GetFiles(
                    folderPath
                    , "*." + fileExtention.Replace(".", "")
                    , System.IO.SearchOption.AllDirectories
                    );

                foreach (string fileName in fileNames)
                {
                    if (fileName.Replace(folderPath, "").Substring(0, firstNamePart.Length) == firstNamePart)
                    {
                        return(fileName);
                    }
                }
            }

            return("");
        }