Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
Hello,

How to image save without using FileUpload Control in c# asp.net?
I have a simple imagebox and I want to image save of this image box, in to the path or folder.

I am trying this jquery code for upload image.
Fileupload.prototype.change = function (e) {
      if (e.target.files === undefined) e.target.files = e.target && e.target.value ? [{ name: e.target.value.replace(/^.+\\/, '')}] : []
      if (e.target.files.length === 0) return

      this.$hidden.val('')
      this.$hidden.attr('name', '')
      this.$input.attr('name', this.name)

      var file = e.target.files[0]

      if (this.$preview.length > 0 && (typeof file.type !== "undefined" ? file.type.match('image.*') : file.name.match(/\.(gif|png|jpe?g)$/i)) && typeof FileReader !== "undefined") {
          var reader = new FileReader()
          var preview = this.$preview
          var element = this.$element

          reader.onload = function (re) {
              var $img = $('<img>').attr('src', re.target.result)
              e.target.files[0].result = re.target.result

              element.find('.fileinput-filename').text(file.name)

              // if parent has max-height, using `(max-)height: 100%` on child doesn't take padding and border into account
              if (preview.css('max-height') != 'none') $img.css('max-height', parseInt(preview.css('max-height'), 10) - parseInt(preview.css('padding-top'), 10) - parseInt(preview.css('padding-bottom'), 10) - parseInt(preview.css('border-top'), 10) - parseInt(preview.css('border-bottom'), 10))

              preview.html($img)
              element.addClass('fileinput-exists').removeClass('fileinput-new')

              element.trigger('change.bs.fileinput', e.target.files)
              $('#HFLogoPath').val(file.name);

          }

          reader.readAsDataURL(file)
          
      } else {
          this.$element.find('.fileinput-filename').text(file.name)
          this.$preview.text(file.name)

          this.$element.addClass('fileinput-exists').removeClass('fileinput-new')

          this.$element.trigger('change.bs.fileinput')
      }
  },

but my image did not save into the my server.mappath.

Please help me.

Thanks in Advance.

Ankit Agarwal
Website Application Developer
Posted
Updated 16-Jan-14 0:51am
v2
Comments
What have you tried and where is the problem?
[no name] 16-Jan-14 6:36am    
I am trying this jquery code for upload image.
Fileupload.prototype.change = function (e) {
if (e.target.files === undefined) e.target.files = e.target && e.target.value ? [{ name: e.target.value.replace(/^.+\\/, '')}] : []
if (e.target.files.length === 0) return

this.$hidden.val('')
this.$hidden.attr('name', '')
this.$input.attr('name', this.name)

var file = e.target.files[0]

if (this.$preview.length > 0 && (typeof file.type !== "undefined" ? file.type.match('image.*') : file.name.match(/\.(gif|png|jpe?g)$/i)) && typeof FileReader !== "undefined") {
var reader = new FileReader()
var preview = this.$preview
var element = this.$element

reader.onload = function (re) {
var $img = $('<img>').attr('src', re.target.result)
e.target.files[0].result = re.target.result

element.find('.fileinput-filename').text(file.name)

// if parent has max-height, using `(max-)height: 100%` on child doesn't take padding and border into account
if (preview.css('max-height') != 'none') $img.css('max-height', parseInt(preview.css('max-height'), 10) - parseInt(preview.css('padding-top'), 10) - parseInt(preview.css('padding-bottom'), 10) - parseInt(preview.css('border-top'), 10) - parseInt(preview.css('border-bottom'), 10))

preview.html($img)
element.addClass('fileinput-exists').removeClass('fileinput-new')

element.trigger('change.bs.fileinput', e.target.files)
$('#HFLogoPath').val(file.name);

}

reader.readAsDataURL(file)

} else {
this.$element.find('.fileinput-filename').text(file.name)
this.$preview.text(file.name)

this.$element.addClass('fileinput-exists').removeClass('fileinput-new')

this.$element.trigger('change.bs.fileinput')
}
},

but my image did not save into the my server.mappath.
bowlturner 16-Jan-14 9:53am    
does the process have write access to the path you are trying to save to?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900