Ejemplo n.º 1
0
        public void writeContents(int id, string filename, Byte[] contents, string username, string password)
        {
            Authenticate(username, password);

            filename = filename.Replace("/", global::Umbraco.Core.IO.IOHelper.DirSepChar.ToString());
            filename = filename.Replace(@"\", global::Umbraco.Core.IO.IOHelper.DirSepChar.ToString());
            filename = filename.Substring(filename.LastIndexOf(global::Umbraco.Core.IO.IOHelper.DirSepChar) + 1, filename.Length - filename.LastIndexOf(global::Umbraco.Core.IO.IOHelper.DirSepChar) - 1).ToLower();

            var m = new Media(id);

            var numberedFolder = MediaSubfolderCounter.Current.Increment();
            var path           = _fs.GetRelativePath(numberedFolder.ToString(CultureInfo.InvariantCulture), filename);

            var stream = new MemoryStream();

            stream.Write(contents, 0, contents.Length);
            stream.Seek(0, 0);

            _fs.AddFile(path, stream);

            m.getProperty("umbracoFile").Value      = _fs.GetUrl(path);
            m.getProperty("umbracoExtension").Value = Path.GetExtension(filename).Substring(1);
            m.getProperty("umbracoBytes").Value     = _fs.GetSize(path);

            m.Save();
        }
Ejemplo n.º 2
0
        private void initialize()
        {
            _fileName  = System.IO.Path.GetFileName(_path);
            _length    = _fs.GetSize(_path);
            _extension = System.IO.Path.GetExtension(_path) != null
                ? System.IO.Path.GetExtension(_path).Substring(1).ToLowerInvariant()
                : "";

            _url = _fs.GetUrl(_path);
        }