GetMimeType() public static method

public static GetMimeType ( string fileName ) : string
fileName string
return string
Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="data"></param>
        /// <param name="pid"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        private string UploadFile(byte[] data, string pid, string fileName)
        {
            var mimeType = DataUtils.GetMimeType(fileName);

            if (pid.Contains("~"))
            {
                return("");
            }
            string dsid = "", output = "";

            using (var srv = GetManagementService())
            {
                dsid = srv.getNextPID("1", "content")[0].Replace(":", "");

                output = srv.addDatastream(pid,
                                           dsid,
                                           new string[] { },
                                           fileName,
                                           true,
                                           mimeType,
                                           "",
                                           "http://www.google.com",
                                           "M",
                                           "A",
                                           "Disabled",
                                           "none",
                                           "add");



                string requestURL = String.Format(BASECONTENTURL, _BaseUrl, pid, output);
                try
                {
                    using (WebClient client = new WebClient())
                    {
                        client.Proxy       = null;
                        client.Credentials = _Credantials;
                        client.Headers.Add("Content-Type", mimeType);
                        client.UploadData(requestURL, data);
                    }
                }
                catch (Exception e)
                {
                    System.Exception e2 = new Exception(requestURL);

                    throw e2;
                }
            }
            return(dsid);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="data"></param>
        /// <param name="pid"></param>
        /// <param name="fileName"></param>
        /// <param name="newFileName"></param>
        /// <returns></returns>
        public string UpdateFile(byte[] data, string pid, string fileName, string newFileName = null)
        {
            var mimeType = "";

            //string destinationFileName = fileName.Replace(Path.GetExtension(fileName), Path.GetExtension(newFileName));
            if (!String.IsNullOrEmpty(newFileName))
            {
                mimeType = DataUtils.GetMimeType(newFileName);
            }
            else
            {
                mimeType = DataUtils.GetMimeType(fileName);
            }
            if (String.IsNullOrEmpty(pid) || String.IsNullOrEmpty(fileName))
            {
                return(String.Empty);
            }
            if (!String.IsNullOrEmpty(newFileName))
            {
                using (var srv = GetManagementService())
                {
                    //srv.modifyDatastreamByReference(pid,
                    //GetDSId(pid, fileName),
                    //new string[0],
                    //newFileName,
                    //mimeType,
                    //"",
                    //GetContentUrl(pid, "Dublin Core Record for this object"),
                    //"Disabled",
                    //"none",
                    //"Add Review",
                    //true
                    //);
                }
            }

            var requestURL = GetContentUrl(pid, GetDSId(pid, fileName));

            requestURL = requestURL.Substring(0, requestURL.LastIndexOf('/'));
            using (WebClient client = new WebClient())
            {
                client.Credentials = _Credantials;
                client.Headers.Add("Content-Type", mimeType);
                client.UploadData(requestURL, "POST", data);
            }

            return(GetDSId(pid, fileName));
        }