protected void Page_Load(object sender, EventArgs e)
    {
        HttpFileCollection files = Request.Files;
        string             msg   = string.Empty;
        string             error = string.Empty;
        string             imgurl;
        string             input = "", DirRoot = "", filename = "";
        int stringindex = 0, cut = 0;

        if (files.Count > 0)
        {
            //files[0].SaveAs(Server.MapPath("/") + System.IO.Path.GetFileName(files[0].FileName));

            msg = "File size:" + files[0].ContentLength;

            input       = files[0].FileName;
            stringindex = input.LastIndexOf(@".");
            cut         = input.Length - stringindex;
            DirRoot     = input.Substring(stringindex + 1, cut - 1);

            // Allow only files less than (16 MB)=16777216 bytes to be uploaded.

            filename = DateTime.Now.ToString("yyyyMMddHHmmssffff") + @"." + DirRoot;

            Google.Apis.Auth.OAuth2.GoogleCredential credential = GCP_AUTH.AuthExplicit();
            imgurl = GCP_AUTH.upload_file_stream("", "upload/nursing_room_customer", filename, files[0].InputStream, credential);


            string res = imgurl;
            Response.Write(res);
            Response.End();
        }
    }
    protected void UploadDocument(object sender, EventArgs e)
    {
        string  input = "", DirRoot = "", filename = "";
        int     stringindex = 0, cut = 0;
        Boolean check = false;

        if (fuDocument.HasFile)
        {
            HttpPostedFile postedFile = fuDocument.PostedFile;

            DirRoot = System.IO.Path.GetExtension(postedFile.FileName).ToUpper().Replace(".", "");

            SqlDataSource2.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
            SqlDataSource2.SelectCommand    = "select id,name from filename_extension";
            SqlDataSource2.DataBind();
            DataView ou1 = (DataView)SqlDataSource2.Select(DataSourceSelectArguments.Empty);
            for (int i = 0; i < ou1.Count; i++)
            {
                if (DirRoot.ToUpper() == ou1.Table.Rows[i]["name"].ToString().ToUpper())
                {
                    check = true;
                }
            }
            if (check)
            {
                int fileSize = fuDocument.PostedFile.ContentLength;

                // Allow only files less than (16 MB)=16777216 bytes to be uploaded.
                if (fileSize < 16777216)
                {
                    SqlDataSource sql_insert = new SqlDataSource();
                    sql_insert.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["connStr"].ConnectionString;

                    filename = DateTime.Now.ToString("yyyyMMddHHmmssffff") + @"." + DirRoot;

                    //AmazonUpload aws = new AmazonUpload();
                    //string imgurl = aws.AmazonUpload_file("makelocal", "upload/test", filename, postedFile.InputStream);

                    Google.Apis.Auth.OAuth2.GoogleCredential credential = GCP_AUTH.AuthExplicit();
                    string imgurl = GCP_AUTH.upload_file_stream("makelocal", "upload/test", filename, postedFile.InputStream, credential);


                    //Label1.Text += fuDocument.FileName.ToString() + "  finish<br>";
                    //fuDocument.SaveAs(Server.MapPath("school_important_images") + "\\" + filename);
                    type0_Image.ImageUrl = imgurl;
                    Image4.Visible       = true;
                    Image5.Visible       = false;
                    //GridView1.DataBind();
                }
                else
                {
                    ScriptManager.RegisterStartupScript(fuDocument, fuDocument.GetType(), "alert", "alert('File is out of memory 16MB!')", true);
                }
            }
            else
            {
                ScriptManager.RegisterStartupScript(fuDocument, fuDocument.GetType(), "alert", "alert('filename extension is not in role!')", true);
            }
        }
    }
    protected void UploadDocument(object sender, EventArgs e)
    {
        string  input = "", DirRoot = "", filename = "";
        int     stringindex = 0, cut = 0;
        Boolean check = false;

        Session["head_photo"] = null;
        if (fuDocument.HasFile)
        {
            HttpPostedFile postedFile = fuDocument.PostedFile;

            DirRoot = System.IO.Path.GetExtension(postedFile.FileName).ToUpper().Replace(".", "");

            Query = "select id,name from filename_extension";
            DataView ou1 = gc.select_cmd(Query);
            for (int i = 0; i < ou1.Count; i++)
            {
                if (DirRoot.ToUpper() == ou1.Table.Rows[i]["name"].ToString().ToUpper())
                {
                    check = true;
                }
            }
            if (check)
            {
                filename = DateTime.Now.ToString("yyyyMMddHHmmssffff") + @"." + DirRoot;

                Google.Apis.Auth.OAuth2.GoogleCredential credential = GCP_AUTH.AuthExplicit();
                string imgurl = GCP_AUTH.upload_file_stream("", "upload/test", filename, postedFile.InputStream, credential);
                //AmazonUpload aws = new AmazonUpload();
                //string imgurl = aws.AmazonUpload_file("", "upload/test", filename, postedFile.InputStream);

                //fuDocument.SaveAs(Server.MapPath("head_photo") + "\\" + filename);
                Image1.ImageUrl = imgurl;
                Image1.Attributes.Add("style", "display:block");

                Session["head_photo"] = "~/" + imgurl;
            }
            else
            {
                ScriptManager.RegisterStartupScript(fuDocument, fuDocument.GetType(), "alert", "alert('filename extension is not in role!')", true);
            }
        }
    }
    protected void UploadDocument(object sender, EventArgs e)
    {
        string  input = "", DirRoot = "", filename = "";
        int     stringindex = 0, cut = 0;
        Boolean check = false;


        if (fuDocument.HasFile)
        {
            foreach (HttpPostedFile postedFile in fuDocument.PostedFiles)
            {
                DirRoot = System.IO.Path.GetExtension(postedFile.FileName).ToUpper().Replace(".", "");


                Query = "select id,name from filename_extension";
                DataView ou1 = gc.select_cmd(Query);
                for (int i = 0; i < ou1.Count; i++)
                {
                    if (DirRoot.ToUpper() == ou1.Table.Rows[i]["name"].ToString().ToUpper())
                    {
                        check = true;
                    }
                }
                if (check)
                {
                    int fileSize = postedFile.ContentLength;

                    // Allow only files less than (16 MB)=16777216 bytes to be uploaded.
                    if (fileSize < 16777216)
                    {
                        filename = DateTime.Now.ToString("yyyyMMddHHmmssffff") + @"." + DirRoot;


                        //AmazonUpload aws = new AmazonUpload();
                        //string imgurl = aws.AmazonUpload_file("", "upload/test", filename, postedFile.InputStream);

                        Google.Apis.Auth.OAuth2.GoogleCredential credential = GCP_AUTH.AuthExplicit();
                        string imgurl = GCP_AUTH.upload_file_stream("", "upload/test", filename, postedFile.InputStream, credential);

                        //AmazonUpload aws = new AmazonUpload();
                        //string imgurl = aws.AmazonUpload_file("", "upload/test", filename, postedFile.InputStream);

                        Image im = new Image();
                        im.Width    = 100;
                        im.Height   = 100;
                        im.ImageUrl = imgurl;
                        this.Panel1.Controls.Add(im);

                        image_HiddenField.Value += ",~/" + imgurl;



                        //upload_files.Text += Server.MapPath("fileplace") + "\\" + filename + ",";
                        //upload_files0.Text += postedFile.FileName.ToString() + ",";
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(fuDocument, fuDocument.GetType(), "alert", "alert('File is out of memory 16MB!')", true);
                    }
                }
                else
                {
                    ScriptManager.RegisterStartupScript(fuDocument, fuDocument.GetType(), "alert", "alert('filename extension is not in role!')", true);
                }
            }
        }
    }
    protected void UploadDocument(object sender, EventArgs e)
    {
        string  input = "", DirRoot = "", filename = "";
        int     stringindex = 0, cut = 0;
        Boolean check = false;

        if (fuDocument.HasFile)
        {
            Panel1.Attributes.Add("style", "display:block");
            impath = new List <string>();
            Panel1.Controls.Clear();
            foreach (HttpPostedFile postedFile in fuDocument.PostedFiles)
            {
                DirRoot = System.IO.Path.GetExtension(postedFile.FileName).ToUpper().Replace(".", "");

                SqlDataSource2.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
                SqlDataSource2.SelectCommand    = "select id,name from filename_extension";
                SqlDataSource2.DataBind();
                DataView ou1 = (DataView)SqlDataSource2.Select(DataSourceSelectArguments.Empty);
                for (int i = 0; i < ou1.Count; i++)
                {
                    if (DirRoot.ToUpper() == ou1.Table.Rows[i]["name"].ToString().ToUpper())
                    {
                        check = true;
                    }
                }
                if (check)
                {
                    int fileSize = postedFile.ContentLength;

                    // Allow only files less than (16 MB)=16777216 bytes to be uploaded.
                    if (fileSize < 16777216)
                    {
                        SqlDataSource sql_insert = new SqlDataSource();
                        sql_insert.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["connStr"].ConnectionString;

                        filename = DateTime.Now.ToString("yyyyMMddHHmmssffff") + @"." + DirRoot;

                        //AmazonUpload aws = new AmazonUpload();
                        //string imgurl = aws.AmazonUpload_file("", "upload/test", filename, postedFile.InputStream);

                        Google.Apis.Auth.OAuth2.GoogleCredential credential = GCP_AUTH.AuthExplicit();
                        string imgurl = GCP_AUTH.upload_file_stream("", "upload/test", filename, postedFile.InputStream, credential);

                        Image im = new Image();
                        im.Width    = 100;
                        im.Height   = 100;
                        im.ImageUrl = imgurl;
                        impath.Add(@"~/" + imgurl);
                        this.Panel1.Controls.Add(im);

                        //Image1.ImageUrl = Server.MapPath("fileplace") + "\\" + filename;


                        //upload_files.Text += Server.MapPath("fileplace") + "\\" + filename + ",";
                        //upload_files0.Text += postedFile.FileName.ToString() + ",";
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(fuDocument, fuDocument.GetType(), "alert", "alert('File is out of memory 16MB!')", true);
                    }
                }
                else
                {
                    ScriptManager.RegisterStartupScript(fuDocument, fuDocument.GetType(), "alert", "alert('filename extension is not in role!')", true);
                }
            }



            ViewState["myData"] = impath;
        }
    }