コード例 #1
0
ファイル: admin_ajax.ashx.cs プロジェクト: eryueren/OScms
        private void get_remote_fileinfo(HttpContext context)
        {
            string filePath = OSRequest.GetFormString("remotepath");

            if (string.IsNullOrEmpty(filePath))
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"没有找到远程附件地址!\"}");
                return;
            }
            if (!filePath.ToLower().StartsWith("http://"))
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"不是远程附件地址!\"}");
                return;
            }
            try
            {
                HttpWebRequest  _request  = (HttpWebRequest)WebRequest.Create(filePath);
                HttpWebResponse _response = (HttpWebResponse)_request.GetResponse();
                int             fileSize  = (int)_response.ContentLength;
                string          fileName  = filePath.Substring(filePath.LastIndexOf("/") + 1);
                string          fileExt   = filePath.Substring(filePath.LastIndexOf(".") + 1).ToUpper();
                context.Response.Write("{\"status\": 1, \"msg\": \"获取远程文件成功!\", \"name\": \"" + fileName + "\", \"path\": \"" + filePath + "\", \"size\": " + fileSize + ", \"ext\": \"" + fileExt + "\"}");
            }
            catch
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"远程文件不存在!\"}");
                return;
            }
        }
コード例 #2
0
ファイル: admin_ajax.ashx.cs プロジェクト: eryueren/OScms
        private void create_folder(HttpContext context)
        {
            string _name      = OSRequest.GetFormString("_name");
            string folderName = OSRequest.GetFormString("folderName");

            if (string.IsNullOrEmpty(folderName))
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"文件夹名称不可为空!\"}");
                return;
            }
            if (string.IsNullOrEmpty(_name))
            {
                try
                {
                    DirectoryInfo di = new DirectoryInfo(Utils.GetMapPath(@"../Template/" + folderName));
                    if (di.Exists)
                    {
                        context.Response.Write("{\"status\": 0, \"msg\": \"该文件夹已经存在,请更换!\"}");
                        return;
                    }
                    else
                    {
                        di.Create();
                        context.Response.Write("{\"status\": 1, \"msg\": \"创建文件夹成功!\"}");
                        return;
                    }
                }
                catch (Exception error)
                {
                    context.Response.Write("{ \"info\":\"创建文件夹失败!失败原因:" + error.ToString() + "\", \"status\":\"n\" }");
                    return;
                }
            }
            else
            {
                if (_name == folderName)
                {
                    context.Response.Write("{\"status\": 1, \"msg\": \"更改文件名成功!\"}");
                    return;
                }
                try
                {
                    DirectoryInfo di = new DirectoryInfo(Utils.GetMapPath(@"../Template/" + _name));
                    if (di.Exists)
                    {
                        di.MoveTo(Utils.GetMapPath(@"../Template/" + folderName));
                        context.Response.Write("{\"status\": 1, \"msg\": \"更改文件名成功!\"}");
                        return;
                    }
                }
                catch (Exception error)
                {
                    context.Response.Write("{ \"info\":\"更改文件名成功失败!原因:" + error.ToString() + "\", \"status\":\"n\" }");
                    return;
                }
            }
        }