TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Publish Image to Umbraco Media Library
S Ravindran
May 12, 2014
11.7
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
Code for publishing images to the media library using C# and umbraco.
public
class
MediaClass
{
public
HttpPostedFileBase
file {
get
;
set
; }
public
string
FileNameAlias {
get
;
set
; }
public
string
NameOfImage {
get
;
set
; }
public
string
ParentMediaName {
get
;
set
; }
}
protected
int
AddImageToUmbraco(
MediaClass
mediaClass)
{
var
ms = Services.MediaService;
var
newFile = ms.CreateMedia(mediaClass.NameOfImage,
uQuery
.GetMediaByName(mediaClass.ParentMediaName).FirstOrDefault().Id,
"Image"
, member.Id);
newFile.SetValue(
"umbracoFile"
, mediaClass.file);
ms.Save(newFile);
return
newFile.Id;
//return the id of newly created image
}
Publish image to umbraco media library
Next Recommended Reading
Image Conversion And Storing The Image Value Using C#