Example #1
0
        /// <summary>
        /// Registers the startup script.
        /// </summary>
        private void RegisterStartupScript()
        {
            var postBackScript = this.Page.ClientScript.GetPostBackEventReference(new PostBackOptions(this._fileUpload, "FileUploaded"), true);

            postBackScript = postBackScript.Replace('\'', '"');
            var script = string.Format(
                @"
Rock.controls.fileUploader.initialize({{
    controlId: '{0}',
    fileId: '{1}',
    fileTypeGuid: '{2}',
    hfFileId: '{3}',
    aFileName: '{4}',
    aRemove: '{5}',
    postbackScript: '{6}',
    fileType: 'file'
}});",
                _fileUpload.ClientID,
                BinaryFileId,
                BinaryFileTypeGuid,
                _hfBinaryFileId.ClientID,
                _aFileName.ClientID,
                _aRemove.ClientID,
                postBackScript);

            ScriptManager.RegisterStartupScript(_fileUpload, _fileUpload.GetType(), "FileUploaderScript_" + this.ClientID, script, true);
        }
Example #2
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init"/> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            EnsureChildControls();

            var script = string.Format(
                @"
Rock.controls.imageUploader.initialize({{
    controlId: '{0}',
    fileId: '{1}',
    fileTypeGuid: '{2}',
    hfFileId: '{3}',
    imgThumbnail: '{4}',
    aRemove: '{5}',
    fileType: 'image'
}});",
                _fileUpload.ClientID,
                BinaryFileId,
                BinaryFileTypeGuid,
                _hfBinaryFileId.ClientID,
                _imgThumbnail.ClientID,
                _aRemove.ClientID);

            ScriptManager.RegisterStartupScript(_fileUpload, _fileUpload.GetType(), "ImageUploaderScript_" + this.ID, script, true);
        }
Example #3
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init"/> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param>
        protected override void OnInit(System.EventArgs e)
        {
            base.OnInit(e);

            EnsureChildControls();

            string script = string.Format(@"
    $(document).ready(function() {{

        function ConfigureImageUploaders(sender, args) {{
            $('#{0}').kendoUpload({{
                multiple: false,
                showFileList: false,
                async: {{
                    saveUrl: '{4}ImageUploader.ashx'
                }},

                success: function(e) {{

                    if (e.operation == 'upload' && e.response != '0') {{
                        $('#{1}').val(e.response);
                        $('#{2}').attr('src','')
                        $('#{2}').hide();             
                        $('#{2}').attr('src','{4}Image.ashx?id=' + e.response + '&width=50&height=50');
                        $('#{2}').show('fast', function() {{ 
                            if ($('#modal-scroll-container').length) {{
                                $('#modal-scroll-container').tinyscrollbar_update('relative');
                            }}
                        }});
                        $('#{3}').show('fast');
                    }}

                }}
            }});

            $('#{3}').click( function(){{
                $(this).hide('fast');
                $('#{1}').val('0');
                $('#{2}').attr('src','')
                $('#{2}').hide('fast', function() {{ 
                    if ($('#modal-scroll-container').length) {{
                        $('#modal-scroll-container').tinyscrollbar_update('relative');
                    }}
                }});
            }});

        }}

        // configure image uploaders         
        ConfigureImageUploaders(null, null);
    }});
        ",
                                          fileUpload.ClientID,
                                          hiddenField.ClientID,
                                          image.ClientID,
                                          htmlAnchor.ClientID,
                                          ResolveUrl("~"));

            ScriptManager.RegisterStartupScript(fileUpload, fileUpload.GetType(), "KendoImageScript_" + this.ID, script, true);
        }
Example #4
0
        /// <summary>
        /// Registers the startup script.
        /// </summary>
        private void RegisterStartupScript()
        {
            int?maxUploadBytes = null;

            try
            {
                HttpRuntimeSection section = ConfigurationManager.GetSection("system.web/httpRuntime") as HttpRuntimeSection;
                if (section != null)
                {
                    // MaxRequestLength is in KB
                    maxUploadBytes = section.MaxRequestLength * 1024;
                }
            }
            catch
            {
                // intentionally ignore and don't tell the fileUploader the limit
            }

            var postBackScript = this.FileUploaded != null?this.Page.ClientScript.GetPostBackEventReference(new PostBackOptions( this, "FileUploaded" ), true) : "";

            postBackScript = postBackScript.Replace('\'', '"');
            var script = string.Format(
                @"
Rock.controls.fileUploader.initialize({{
    controlId: '{0}',
    fileId: '{1}',
    fileTypeGuid: '{2}',
    hfFileId: '{3}',
    aFileName: '{4}',
    aRemove: '{5}',
    postbackScript: '{6}',
    fileType: 'file',
    isBinaryFile: '{7}',
    rootFolder: '{8}',
    uploadUrl: '{9}',
    submitFunction: function (e, data) {{
        {10}
    }},
    doneFunction: function (e, data) {{
        {11}
    }},
    maxUploadBytes: {12}
}});",
                _fileUpload.ClientID,
                this.BinaryFileId,
                this.BinaryFileTypeGuid,
                _hfBinaryFileId.ClientID,
                _aFileName.ClientID,
                _aRemove.ClientID,
                postBackScript,
                this.IsBinaryFile ? "T" : "F",
                Rock.Security.Encryption.EncryptString(this.RootFolder),
                this.UploadUrl,
                this.SubmitFunctionClientScript,
                this.DoneFunctionClientScript,
                maxUploadBytes.HasValue ? maxUploadBytes.Value.ToString() : "null");

            ScriptManager.RegisterStartupScript(_fileUpload, _fileUpload.GetType(), "FileUploaderScript_" + this.ClientID, script, true);
        }
Example #5
0
        /// <summary>
        /// Registers the startup script.
        /// </summary>
        private void RegisterStartupScript()
        {
            int?maxUploadBytes = null;

            try
            {
                HttpRuntimeSection section = ConfigurationManager.GetSection("system.web/httpRuntime") as HttpRuntimeSection;
                if (section != null)
                {
                    // MaxRequestLength is in KB
                    maxUploadBytes = section.MaxRequestLength * 1024;
                }
            }
            catch
            {
                // intentionally ignore and don't tell the fileUploader the limit
            }

            var jsDoneFunction = string.Format("window.location = $('#{0}').prop('href');", _lbUploadImage.ClientID);

            var script = string.Format(
                @"
Rock.controls.imageUploader.initialize({{
    controlId: '{0}',
    fileId: '{1}',
    fileTypeGuid: '{2}',
    hfFileId: '{3}',
    imgThumbnail: '{4}',
    aRemove: '{5}',
    fileType: 'image',
    setImageUrlOnUpload: false,
    noPictureUrl: '{11}',
    doneFunction: function (e, data) {{
        // toggle the edit/upload buttons
        $('#{8}').hide();
        $('#{9}').show();

        // postback to show Modal after uploading new image
        {10}
    }},
    maxUploadBytes: {12}
}});

$('#{6}').Jcrop({{
    aspectRatio:1,
    setSelect:   [0,0, $('#{6}').width(), $('#{6}').height() ],
    boxWidth:480,
    boxHeight:480,
    onSelect: function(c) {{
        $('#{7}').val(c.x.toFixed() + ',' + c.y.toFixed() + ',' + c.w.toFixed() + ',' + c.h.toFixed() + ',');
    }}
}});

// prompt to upload image
$('#{8}').click( function (e, data) {{
    $('#{0}').click();
}});

// hide/show buttons and remove this button when remove is clicked (note: imageUploader.js also does stuff when remove is clicked)
$('#{5}').click(function () {{
    $('#{8}').show();
    $('#{9}').hide();
    $('#{5}').remove();
}});

",
                _fileUpload.ClientID,                                              // {0}
                this.BinaryFileId,                                                 // {1}
                this.BinaryFileTypeGuid,                                           // {2}
                _hfBinaryFileId.ClientID,                                          // {3}
                this.ClientID + "_divPhoto",                                       // {4}
                _aRemove.ClientID,                                                 // {5}
                _imgCropSource.ClientID,                                           // {6}
                _hfCropCoords.ClientID,                                            // {7}
                _lbUploadImage.ClientID,                                           // {8}
                _lbShowModal.ClientID,                                             // {9}
                jsDoneFunction,                                                    // {10}
                this.NoPictureUrl,                                                 // {11}
                maxUploadBytes.HasValue ? maxUploadBytes.Value.ToString() : "null" // {12}
                );

            _lbUploadImage.Enabled = false;

            ScriptManager.RegisterStartupScript(_fileUpload, _fileUpload.GetType(), "ImageUploaderScript_" + this.ClientID, script, true);
        }
Example #6
0
    protected void UploadDocument(object sender, EventArgs e)
    {
        string  input = "", DirRoot = "", filename = "";
        int     stringindex = 0, cut = 0;
        Boolean check    = false;
        Button  temp     = (Button)sender;
        string  idcut    = temp.ID;
        int     startind = idcut.LastIndexOf(@"_");
        string  cutstr   = idcut.Substring(startind + 1, idcut.Length - startind - 1);

        FileUpload fuDocument = (FileUpload)this.FindControl("fuDocument_" + cutstr);

        if (fuDocument.HasFile)
        {
            input       = fuDocument.FileName;
            stringindex = input.LastIndexOf(@".");
            cut         = input.Length - stringindex;
            DirRoot     = input.Substring(stringindex + 1, cut - 1);

            SqlDataSource1.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
            SqlDataSource1.SelectCommand    = "select id,name from filename_extension";
            SqlDataSource1.DataBind();
            DataView ou1 = (DataView)SqlDataSource1.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;

                    //sql_insert.InsertCommand = "insert into filename_detail(filename,name)";
                    //sql_insert.InsertCommand += " values('~/fileplace/" + filename + "','" + fuDocument.FileName.ToString() + "')";
                    //sql_insert.Insert();

                    //Label1.Text += fuDocument.FileName.ToString() + "  finish<br>";
                    fuDocument.SaveAs(Server.MapPath("fileplace") + "\\" + filename);
                    Image img = (Image)this.FindControl("Image_" + cutstr);
                    img.ImageUrl = "~/fileplace/" + filename;
                    img.Visible  = true;
                    //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);
            }
        }
    }
Example #7
0
        /// <summary>
        /// Registers the startup script.
        /// </summary>
        private void RegisterStartupScript()
        {
            int?maxUploadBytes = null;

            try
            {
                HttpRuntimeSection section = ConfigurationManager.GetSection("system.web/httpRuntime") as HttpRuntimeSection;
                if (section != null)
                {
                    // MaxRequestLength is in KB
                    maxUploadBytes = section.MaxRequestLength * 1024;
                }
            }
            catch
            {
                // intentionally ignore and don't tell the fileUploader the limit
            }

            var postBackScript = this.ImageUploaded != null?this.Page.ClientScript.GetPostBackEventReference(new PostBackOptions( this, "ImageUploaded" ), true) : "";

            postBackScript = postBackScript.Replace('\'', '"');

            // If in BinaryFile mode, only do an ImageRemoved postback if there is a ImageRemoved event specified
            // If in ContentFile mode, do the postback regardless since we'll have to delete the contentfile from the system
            bool doImageRemovedPostback = this.ImageRemoved != null || this.IsBinaryFile == false;

            var postBackRemovedScript = doImageRemovedPostback ? this.Page.ClientScript.GetPostBackEventReference(new PostBackOptions(this, "ImageRemoved"), true) : "";

            postBackRemovedScript = postBackRemovedScript.Replace('\'', '"');

            var script =
                $@"
Rock.controls.imageUploader.initialize({{
    controlId: '{_fileUpload.ClientID}',
    fileId: '{this.BinaryFileId}',
    fileTypeGuid: '{this.BinaryFileTypeGuid}',
    hfFileId: '{_hfBinaryFileId.ClientID}',
    hfContentFileSource: '{_hfContentFileSource.ClientID}',
    imgThumbnail: '{( this.ClientID + "-thumbnail" )}',
    aRemove: '{_aRemove.ClientID}',
    postbackScript: '{postBackScript}',
    fileType: 'image',
    isBinaryFile: '{( this.IsBinaryFile ? "T" : "F" )}',
    rootFolder: '{Rock.Security.Encryption.EncryptString( this.RootFolder )}',
    noPictureUrl: '{this.NoPictureUrl}',
    submitFunction: function (e, data) {{
        {this.SubmitFunctionClientScript}
    }},
    doneFunction: function (e, data) {{
        {this.DoneFunctionClientScript}
    }},
    postbackRemovedScript: '{postBackRemovedScript}',
    maxUploadBytes: {( maxUploadBytes.HasValue ? maxUploadBytes.Value.ToString() : "null" )},
    isTemporary: '{( this.UploadAsTemporary ? "T" : "F" )}',
    deleteFunction: function(e, data) {{
        {this.DeleteFunctionClientScript}
    }}
}});";

            ScriptManager.RegisterStartupScript(_fileUpload, _fileUpload.GetType(), "ImageUploaderScript_" + this.ClientID, script, true);
        }
Example #8
0
        /// <summary>
        /// Registers the startup script.
        /// </summary>
        private void RegisterStartupScript()
        {
            int?maxUploadBytes = null;

            try
            {
                HttpRuntimeSection section = ConfigurationManager.GetSection("system.web/httpRuntime") as HttpRuntimeSection;
                if (section != null)
                {
                    // MaxRequestLength is in KB
                    maxUploadBytes = section.MaxRequestLength * 1024;
                }
            }
            catch
            {
                // intentionally ignore and don't tell the fileUploader the limit
            }

            var postBackScript = this.ImageUploaded != null?this.Page.ClientScript.GetPostBackEventReference(new PostBackOptions( this, "ImageUploaded" ), true) : "";

            postBackScript = postBackScript.Replace('\'', '"');

            var postBackRemovedScript = this.ImageRemoved != null?this.Page.ClientScript.GetPostBackEventReference(new PostBackOptions( this, "ImageRemoved" ), true) : "";

            postBackRemovedScript = postBackRemovedScript.Replace('\'', '"');

            var script = string.Format(
                @"
Rock.controls.imageUploader.initialize({{
    controlId: '{0}',
    fileId: '{1}',
    fileTypeGuid: '{2}',
    hfFileId: '{3}',
    imgThumbnail: '{4}',
    aRemove: '{5}',
    postbackScript: '{6}',
    fileType: 'image',
    isBinaryFile: '{7}',
    rootFolder: '{8}',
    noPictureUrl: '{11}',
    submitFunction: function (e, data) {{
        {9}
    }},
    doneFunction: function (e, data) {{
        {10}
    }},
    postbackRemovedScript: '{12}',
    maxUploadBytes: {13},
    isTemporary: '{14}',
    deleteFunction: function(e, data) {{
        {15}
    }}
}});",
                _fileUpload.ClientID,                                               // {0}
                this.BinaryFileId,                                                  // {1}
                this.BinaryFileTypeGuid,                                            // {2}
                _hfBinaryFileId.ClientID,                                           // {3}
                this.ClientID + "-thumbnail",                                       // {4}
                _aRemove.ClientID,                                                  // {5}
                postBackScript,                                                     // {6}
                this.IsBinaryFile ? "T" : "F",                                      // {7}
                Rock.Security.Encryption.EncryptString(this.RootFolder),            // {8}
                this.SubmitFunctionClientScript,                                    // {9}
                this.DoneFunctionClientScript,                                      // {10}
                this.NoPictureUrl,                                                  // {11}
                postBackRemovedScript,                                              // {12}
                maxUploadBytes.HasValue ? maxUploadBytes.Value.ToString() : "null", // {13}
                this.UploadAsTemporary ? "T" : "F",                                 // {14}
                this.DeleteFunctionClientScript                                     // {15}
                );

            ScriptManager.RegisterStartupScript(_fileUpload, _fileUpload.GetType(), "ImageUploaderScript_" + this.ClientID, script, true);
        }