Inheritance: System.Web.UI.Page
示例#1
0
 protected void Button4_Click(object sender, EventArgs e)
 {
     string res;
     upload up = new upload();
     res = up.Up(File2, "../uploads/");
     this.Label2.Visible = true;
     this.Label2.Text = up.Resup[Convert.ToInt32(res)];
     this.txtMusicPath.Text = up.s;
 }
示例#2
0
    protected void Button4_Click(object sender, EventArgs e)
    {
        string res;
        upload up = new upload();

        res = up.Up(File2, "../uploads/");
        this.Label2.Visible    = true;
        this.Label2.Text       = up.Resup[Convert.ToInt32(res)];
        this.txtMusicPath.Text = up.s;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string res;
        upload up = new upload();

        res = up.Up(file1, "uploads/");
        this.Label1.Visible = true;
        this.Label1.Text    = up.Resup[Convert.ToInt32(res)];
        this.pic.Text       = up.s;
    }
示例#4
0
 protected void Button3_Click(object sender, EventArgs e)
 {
     string res;
     upload up = new upload();
     res = up.Up(file1, "../uploads/");
     this.Label1.Visible = true;
     this.Label1.Text = up.Resup[Convert.ToInt32(res)];
     this.pic.Text = up.s;
     Image1.ImageUrl = "../" + pic.Text;
 }
    protected void Button3_Click(object sender, EventArgs e)
    {
        string res;
        upload up = new upload();

        res = up.Up(file1, "../userfiles/");
        this.Label2.Visible = true;
        this.Label2.Text    = up.Resup[Convert.ToInt32(res)];
        this.pic.Text       = up.s;
        Image2.ImageUrl     = "../userfiles/" + pic.Text;
    }
示例#6
0
    protected void updataImg_Click(object sender, EventArgs e)
    {
        string res;
        upload up = new upload();

        res = up.Up(file1, "/files/");
        this.Label1.Visible = true;
        this.Label1.Text    = up.Resup[Convert.ToInt32(res)];
        this.pic.Text       = up.s;
        Image1.ImageUrl     = "/files/" + pic.Text;
    }
示例#7
0
        public IHttpActionResult Getupload(int id)
        {
            upload upload = db.upload.Find(id);

            if (upload == null)
            {
                return(NotFound());
            }

            return(Ok(upload));
        }
示例#8
0
    protected void Button3_Click(object sender, EventArgs e)
    {
        string res;
        upload up = new upload();

        res = up.Up(File2, "../files/");

        this.Label2.Visible = true;
        this.Label2.Text    = up.Resup[Convert.ToInt32(res)];
        this.TextBox2.Text  = up.s;
        Image1.ImageUrl     = "../files/" + up.s;
    }
示例#9
0
        public IHttpActionResult Postupload(upload upload)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.upload.Add(upload);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = upload.up_id }, upload));
        }
示例#10
0
    protected void Button2_Click(object sender, EventArgs e)
    {
        //这里是文件上传上传用户的头像
        string res;
        upload up = new upload();

        res = up.Up(file1, "files/");
        this.Label1.Visible = true;
        this.Label1.Text    = up.Resup[Convert.ToInt32(res)];
        this.pic.Text       = up.s;
        Image1.ImageUrl     = "files/" + pic.Text;
    }
示例#11
0
        public ActionResult Index(HttpPostedFileBase file)
        {
            string realpath = Server.MapPath("/images") + "//" + file.FileName;

            file.SaveAs(realpath);

            upload u = new upload();

            u.path = file.FileName;
            _db.uploads.Add(u);
            _db.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
示例#12
0
        public IHttpActionResult Deleteupload(int id)
        {
            upload upload = db.upload.Find(id);

            if (upload == null)
            {
                return(NotFound());
            }

            db.upload.Remove(upload);
            db.SaveChanges();

            return(Ok(upload));
        }
示例#13
0
 public ActionResult FileUpload(upload mRegister)
 {
     //Check server side validation using data annotation
     if (ModelState.IsValid)
     {
         //TO:DO
         var fileName = Path.GetFileName(mRegister.file.FileName);
         var path     = Path.Combine(Server.MapPath("~/Content/Upload"), fileName);
         mRegister.file.SaveAs(path);
         ViewBag.Message = "File has been uploaded successfully";
         ModelState.Clear();
     }
     return(View("upload"));
 }
示例#14
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        string res;
        upload up = new upload();

        res = up.Up3(File1, "/lwhPersonal/uploads/excel/", "student");

        if (Convert.ToInt32(res) == 3)
        {
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + up.s3 + ";Extended Properties=Excel 8.0";
            //链接Excel
            OleDbConnection cnnxls = new OleDbConnection(strConn);
            //读取Excel里面有 表Sheet1
            OleDbDataAdapter oda = new OleDbDataAdapter("select * from [Sheet1$]", cnnxls);
            DataSet          ds  = new DataSet();
            //将Excel里面有表内容装载到内存表中!
            oda.Fill(ds);
            DataTable dt = ds.Tables[0];
            try
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string sql1 = "SELECT classId FROM class WHERE name = N'" + dt.Rows[i]["class"].ToString().Trim() + "'";
                    string sql2 = "SELECT COUNT(*) FROM studentlist WHERE name = N'" + dt.Rows[i]["userName"] + "'";
                    string sql3 = "SELECT COUNT(*) FROM studentlist WHERE studyNum = N'" + dt.Rows[i]["studyNum"] + "'";
                    string sql4 = "SELECT COUNT(*) FROM studentlist WHERE sclass = " + Convert.ToInt32(DB.FindString(sql1)) + " AND classNum = " + Convert.ToInt32(dt.Rows[i]["classNum"]) + " ";
                    if (Convert.ToInt32(DB.FindString(sql2)) == 0 && Convert.ToInt32(DB.FindString(sql3)) == 0 && Convert.ToInt32(DB.FindString(sql4)) == 0)
                    {
                        string sql = "INSERT INTO studentlist(name,nickname,password,sclass,studyNum,classNum)VALUES(N'" + dt.Rows[i]["userName"] + "',N'" + dt.Rows[i]["name"] + "',N'" + MD5.Hash(dt.Rows[i]["password"].ToString()) + "'," + Convert.ToInt32(DB.FindString(sql1)) + ",N'" + dt.Rows[i]["studyNum"] + "','" + Convert.ToInt32(dt.Rows[i]["classNum"]) + "')";
                        DB.execnonsql(sql);
                    }
                }
                Response.Write("<script>alert('导入成功!');</script>");
            }
            catch { Response.Write("<script>alert('导入出错,请检查excel表!');</script>"); }
        }
        else
        {
            Response.Write("<script>alert('" + up.Resup3[Convert.ToInt32(res)] + "');</script>");
            //this.Label1.Visible = true;
            //this.Label1.Text = up.Resup3[Convert.ToInt32(res)];
        }
    }
        public HttpResponseMessage Upload()
        {
            var db = new Entities();
            HttpResponseMessage result;
            var httpRequest = HttpContext.Current.Request;

            Debug.WriteLine("upload start");
            var resultAry = new Dictionary <string, dynamic>();

            if (httpRequest.Files.Count > 0)
            {
                var docfiles   = new List <string>();
                var postedFile = httpRequest.Files[0];
                Debug.WriteLine(httpRequest.Files[0].FileName);
                var filePath = HttpContext.Current.Server.MapPath("~/FileUploads/" + postedFile.FileName);
                postedFile.SaveAs(filePath);

                resultAry.Add("file_name", postedFile.FileName);
                resultAry.Add("file_path", filePath);
                FileInfo fi = new FileInfo(filePath);
                resultAry.Add("file_size", fi.Length);

                //resultAry.Add("import_result", importDB);
                Debug.WriteLine(httpRequest["up_user"]);
                upload upload = new upload();
                upload.up_user     = httpRequest["up_user"];
                upload.up_message  = httpRequest["up_message"];
                upload.up_path     = Path.GetDirectoryName(filePath);
                upload.up_filename = postedFile.FileName;
                upload.up_date     = DateTime.Now;
                upload.up_size     = fi.Length;
                db.upload.Add(upload);
                db.SaveChanges();
                resultAry.Add("up_row", upload);
                result = Request.CreateResponse(HttpStatusCode.Created, resultAry);
            }
            else
            {
                result = Request.CreateResponse(HttpStatusCode.BadRequest);
            }
            return(result);
        }
示例#16
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        string res;
        upload up = new upload();

        res = up.Up(file1, "../uploads/hp/");
        this.Label1.Visible = true;
        this.Label1.Text    = up.Resup[Convert.ToInt32(res)];
        this.pic.Text       = up.s;
        this.demo.Text      = up.s;

        string res1;
        upload up1 = new upload();

        res1 = up1.Up(file2, "../uploads/zz/");
        this.Label2.Visible = true;
        this.Label2.Text    = up1.Resup[Convert.ToInt32(res1)];
        this.pic2.Text      = up1.s1;
        this.demo1.Text     = up1.s1;

        string res2;
        upload up2 = new upload();

        res2 = up2.Up(file3, "../uploads/zs/");
        this.Label3.Visible = true;
        this.Label3.Text    = up2.Resup[Convert.ToInt32(res2)];
        this.pic3.Text      = up2.s2;
        this.demo2.Text     = up2.s2;

        string res3;
        upload up3 = new upload();

        res3 = up3.Up(file4, "../uploads/zl/");
        this.Labe14.Visible = true;
        this.Labe14.Text    = up3.Resup[Convert.ToInt32(res3)];
        this.pic4.Text      = up3.s3;
        this.demo5.Text     = up3.s3;

        data.RunSql("insert into pic(name,hp,zz,zs,zl,upload)values('" + Session["danwei"].ToString() + "','" + up.s + "','" + up1.s1 + "','" + up2.s2 + "','" + up3.s3 + "','" + '是' + "')  ");
    }
示例#17
0
        public async void AddQueue()
        {
            string file;

            Console.WriteLine($"队列数量:{queue.Count}");
            if (!queue.TryDequeue(out file))
            {
                adding = false;
                return;
            }
            var f = new System.IO.FileInfo(file);

            try
            {
                if (!f.Exists)
                {
                    return;
                }

                foreach (var item in ignore)
                {
                    if (file.Contains(item))
                    {
                        return;
                    }
                }
                var ext = ExtList.Where(o => o.IsEnabled && o.Name == f.Extension).ToList();
                if (ext.Count == 0)
                {
                    return;
                }
                if (!f.FullName.StartsWith(MainWindow.localRootDir))
                {
                    throw new Exception("根目录异常");
                }
                var task = new TaskInfo {
                    Type = TaskType.步, FullName = f.FullName, Name = f.Name
                };
                using (var stream = Util.GetFileStream(f.FullName))
                {
                    task.sha1 = Util.sha1(stream);
                    task.size = stream.Length;
                }
                if (serverFileCache.ContainsKey(file) && serverFileCache[file] == $"{task.sha1};{task.size}")
                {
                    return;
                }

                string fid = "root";
                if (f.Directory.FullName != MainWindow.localRootDir)
                {
                    var relativeFile = f.Directory.FullName.Substring(MainWindow.localRootDir.Length + 1).Replace("\\", "/") + "/";
                    //dir 所在相对当前路径的目录 格式为 一层目录(aaa/) 二层目录(aaa/bbb/)
                    if (!ParentIDs.ContainsKey(relativeFile))
                    {
                        var ms = Regex.Matches(relativeFile, "([^/]+?)/");
                        var u  = new upload();
                        foreach (Match m in ms)
                        {
                            Console.WriteLine($"同步创建目录[{relativeFile}]:{m.Groups[1].Value}");
                            fid = await u.getfolder(fid, m.Groups[1].Value);
                        }
                        ParentIDs[relativeFile] = fid;
                    }
                    fid = ParentIDs[relativeFile];
                }
                task.parent_file_id = fid;
                var r = await new file().search(fid, f.Name);
                if (!r.Yes)
                {
                    throw new Exception(r.Error);
                }
                if (r.obj.items.Count > 0)
                {
                    foreach (var item in r.obj.items)
                    {
                        serverFileCache[file] = $"{task.sha1};{task.size}";
                        Config_Save();
                        if (item.content_hash == task.sha1 && item.size == task.size)
                        {
                            return;
                        }
                    }
                }

                invoke(() =>
                {
                    TaskMange.Add(task);
                });
            }
            catch (Exception ex)
            {
                invoke(() =>
                {
                    TaskMange.Add(new TaskInfo {
                        Type = TaskType.步, FullName = f.FullName, Status = 3, Name = f.Name + $"[{ex.Error()}]"
                    });
                });
            }
            finally
            {
                _ = Task.Run(AddQueue);
            }
        }
示例#18
0
 false when upload != null && upload is IFormFile => IsValidExtension(upload as IFormFile, extensions),
 true when upload != null && upload is List <IFormFile> => (upload as List <IFormFile>)
        List <upload> uploadRemote(string path)
        {
            List <upload> list = new List <upload>();

            string savePath = PathServerUtility.MapPath(path);       //保存文件地址

            //目录验证
            if (!Directory.Exists(savePath))
            {
                Directory.CreateDirectory(savePath);
            }

            string uri = System.Net.WebUtility.UrlDecode(this.Params("upfile"));

            string[] imgUrls = null;
            if (string.IsNullOrEmpty(uri))
            {
                uri     = System.Net.WebUtility.UrlDecode(this.Params("upfile[]"));
                imgUrls = Regex.Split(uri, ",", RegexOptions.IgnoreCase);
            }
            else
            {
                uri     = uri.Replace("&amp;", "&");
                imgUrls = Regex.Split(uri, "ue_separate_ue", RegexOptions.IgnoreCase);
            }
            for (int i = 0, len = imgUrls.Length; i < len; i++)
            {
                try
                {
                    var imgUrl = imgUrls[i];
                    var upload = new upload {
                        source = imgUrl, state = "SUCCESS"
                    };
                    if (!imgUrl.StartsWith("http://", StringComparison.OrdinalIgnoreCase) &&
                        !imgUrl.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                    //格式验证
                    int temp = imgUrl.LastIndexOf('.');
                    var ext  = imgUrl.Substring(temp).ToLower();
                    if (Array.IndexOf(filetype, ext) == -1)
                    {
                        upload.state = "ERROR";
                        continue;
                    }
                    var stream = HttpUtility.DownBytes(imgUrl);
                    if (stream == null || stream.Length == 0)
                    {
                        continue;
                    }
                    var tmpName = $"{DateTime.Now.ToString("yyyyMMddHHmmssffffff")}_{i}{ext}";
                    //写入文件
                    using (FileStream fs = new FileStream(Path.Combine(savePath, tmpName), FileMode.CreateNew))
                    {
                        //stream.CopyTo(fs);
                        fs.Write(stream, 0, stream.Length);
                        fs.Flush();
                    }

                    upload.url = PathServerUtility.CombineWithRoot(path, tmpName);
                    list.Add(upload);
                }
                catch
                {
                }
            }
            return(list);
        }