Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void btnUpload_Click(object sender, EventArgs e)
- {
- // If no file has been selected, leave the function
- if (uploader.FileBytes.Length == 0 || string.IsNullOrEmpty(uploader.FileName))
- return;
- // Granting privileges
- SPSecurity.RunWithElevatedPrivileges(delegate
- {
- Guid guid = Guid.NewGuid();
- // Picture Library
- SPPictureLibrary list;
- try
- {
- // Retrieve a reference to the picture library
- list = (SPPictureLibrary)Site.RootWeb.Lists["Image Picker Picture List"];
- }
- catch
- {
- // If the library "Image Picker Picture Library" doesn't exists, create the list
- Guid listGuid = Site.RootWeb.Lists.Add("Image Picker Picture List", SPUtility.GetLocalizedString("$Resources:ListDescription", "ImagePicker", SPContext.Current.Web.Language), SPListTemplateType.PictureLibrary);
- list = (SPPictureLibrary)Site.RootWeb.Lists[listGuid];
- list.OnQuickLaunch = false;
- list.Update();
- }
- // Add the picture in the library
- SPFile it = list.RootFolder.Files.Add(guid + uploader.FileName.Substring(uploader.FileName.LastIndexOf('.')), uploader.FileBytes, true);
- // Update the item
- it.Update();
- // Create the Bitmap from the uploaded picture
- Bitmap image = new Bitmap(uploader.FileContent);
- // Get the dimension of the miniature
- Dimension dimensions = Resizer.GetMiniature(image.Width, image.Height);
- // Changing the picture of the parent page
- Page.Response.Write(@"<script language='javascript'>
- opener.document.getElementById('" + Page.Request.QueryString["GUID"] + @"').src = '" + list.ParentWeb.Site.Url + "/" + it.Url + @"';
- opener.document.getElementById('" + Page.Request.QueryString["GUID"] + @"').style.visibility = 'visible';
- opener.document.getElementById('" + Page.Request.QueryString["GUID"] + @"').style.width = '" + dimensions.Width + @"px';
- opener.document.getElementById('" + Page.Request.QueryString["GUID"] + @"').style.height = '" + dimensions.Height + @"px';
- opener.document.getElementById('" + Page.Request.QueryString["path"] + "').value = '" + list.ParentWeb.Site.Url + "/" + it.Url + @"'
- window.close();
- </script>");
- });
- }
Add Comment
Please, Sign In to add comment