Hi.. i have problem.. everything is rendering as it should. Postback occures and in button handler i get 0 files..
ascx code:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UploadItemGalleryImage.ascx.cs" Inherits="IpitchitWeb.UserWebControls.UploadItemGalleryImage" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register Assembly="Microsoft.Web.GeneratedImage" Namespace="Microsoft.Web" TagPrefix="generatedImg" %>
<%@ Register Namespace="Microsoft.Web" TagPrefix="generatedImg" %>
<telerik:RadUpload ID="RadUpload1" runat="server"
MaxFileInputsCount="10" AllowedFileExtensions="gif, jpg, png"
MaxFileSize="5120000" OverwriteExistingFiles="True">
</telerik:RadUpload>
<telerik:RadProgressArea ID="RadProgressArea1" Runat="server">
</telerik:RadProgressArea>
<telerik:RadProgressManager ID="RadProgressManager1" Runat="server" />
<asp:Button ID="btnUploadFiles" runat="server" onclick="UploadFinished"
Text="Upload files to gallery" />
<telerik:RadAjaxPanel runat="server" ID="galleryPanel">
<div>
<asp:Label runat="server" ID="AlbumNameLabel" AssociatedControlID="AlbumName"></asp:Label>
<asp:TextBox runat="server" ID="AlbumName" Text='<%# AlbumTitle %>'></asp:TextBox>
</div>
<div>
<asp:Label runat="server" ID="AlbumDescriptionTitle" AssociatedControlID="AlbumDescriptionText">Album description:</asp:Label>
<asp:TextBox runat="server" ID="AlbumDescriptionText" Text='<%# AlbumDescription %>'></asp:TextBox>
</div>
<div>
<asp:Button runat="server" ID="btnSaveAlbumDetials" Text="Save album details" />
</div>
<asp:DataList runat="server" ID="Gallery" DataSourceID="TempGalleryDataSource" Visible="false">
<HeaderTemplate>
<div>Album</div>
</HeaderTemplate>
<ItemTemplate>
<div>
<asp:Label runat="server" ID="imageAlbumTitle"></asp:Label>
<generatedImg:GeneratedImage ImageHandlerUrl="~/Handlers/GetThumbnail.ashx" runat="server" AlternateText='<%# Eval("Filename") %>'>
<Parameters>
<generatedImg:ImageParameter Name="Width" Value="200" />
<generatedImg:ImageParameter Name="Height" Value="200" />
<generatedImg:ImageParameter Name="Path" Value='<%# Eval("Filename") %>' />
<generatedImg:ImageParameter Name="UseFileSystem" Value="False" />
<generatedImg:ImageParameter Name="CacheToServer" Value="True" />
<generatedImg:ImageParameter Name="CacheToClient" Value="True" />
</Parameters>
</generatedImg:GeneratedImage>
<div>
<span>Main item image:</span>
<asp:LinkButton runat="server" CommandName="MakeFrontImage" CommandArgument='<%# Eval("ImageId") %>'></asp:LinkButton>
</div>
</div>
</ItemTemplate>
</asp:DataList>
<asp:Button runat="server" ID="btnUpdateGalleryImage" Text="Update Gallery" />
</telerik:RadAjaxPanel>
<data:TempGalleriesDataSource runat="server" ID="TempGalleryDataSource"
EnableCaching="false" EnablePaging="false" SelectMethod="GetByFolderId">
<Parameters>
<%--<data:CustomParameter Name="FolderId" Type="Int32" Value='<%# FolderId %>' />--%>
</Parameters>
</data:TempGalleriesDataSource>
codebehind:
namespace IpitchitWeb.UserWebControls
{
public partial class UploadItemGalleryImage : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
//Ipitchit.Data.DataRepository.OriginalImagesProvider.GetAll()
}
private string storePath;
/// <summary>
/// Virtual path for temp folder and that doesn't include Galleries path. Creates folder if it doesn't exist.
/// </summary>
public String StorePath
{
get { return storePath; }
set {
storePath = value;
storePath = Ipitchit.Helper.ImageProcessing.ConvertToServerPath(storePath);
string syspath = storePath + "\\Galleries";
RadUpload1.TargetPhysicalFolder = syspath;
if (!System.IO.Directory.Exists(syspath))
{
try
{
System.IO.Directory.CreateDirectory(syspath);
}
catch (System.Exception ex)
{
throw ex;
}
}
RadUpload1.TargetPhysicalFolder = syspath;
}
}
public int Width { get; set; }
public int Height { get; set; }
private Guid folderId;
public Guid FolderId
{
get
{
if (ViewState["folderId"] != null)
{
folderId = new Guid(ViewState["folderId"].ToString());
}
return folderId;
}
set {
folderId = value;
ViewState["folderId"] = folderId.ToString();
}
}
public string AlbumTitle { get; set; }
public string AlbumDescription { get; set; }
protected void UploadFinished(object sender, EventArgs e)
{
//upload finished.. ready to save files to folders.
// Galeries folder is tempfolder + \Galleries
string SavePath = Server.MapPath(storePath + "/Galleries/");
//TempFolders savelocation = DataRepository.TempFoldersProvider.GetByFolderid(FolderId);
//we know where we will save files.. now we must save them and rezise them correctly.
foreach (Telerik.Web.UI.UploadedFile file in RadUpload1.UploadedFiles)
{
string filename = SavePath + Guid.NewGuid().ToString() + "." + file.GetExtension();
int Width = 600;
int Height = 600;
//saving temp image to database.
var originalImage = new OriginalImages();
Ipitchit.Helper.ImageTransformInfo transformation = Ipitchit.Helper.ImageProcessing.SaveImageAsResized(filename, file.InputStream, Width, Height);
originalImage.Size = transformation.OriginalImage.ImageByteBuffer.Length;
originalImage.Width = transformation.OriginalImage.Image.Width;
originalImage.Height = transformation.OriginalImage.Image.Height;
originalImage.StorageWidth = transformation.ResizedImage.Image.Width;
originalImage.StorageWidth = transformation.ResizedImage.Image.Height;
originalImage.Uploader = this.Page.User.Identity.Name;
originalImage.Created = DateTime.Now;
originalImage.Filename = filename;
originalImage.Alt = AlbumTitle;
originalImage.AlbumTitle = AlbumTitle;
originalImage.AlbumDescription = AlbumDescription;
originalImage.AlbumOrder = 0;
DataRepository.OriginalImagesProvider.Insert(originalImage);
//saving gallery..
var tempgallery = new TempGalleries();
tempgallery.FolderId = this.FolderId;
tempgallery.CreatedDate = DateTime.Now;
tempgallery.ValidDate = DateTime.Now.AddHours(1);
tempgallery.IsFront = false;
tempgallery.ImageId = originalImage.ImageId;
DataRepository.TempGalleriesProvider.Insert(tempgallery);
}
var folderparameter = new Ipitchit.Web.Data.CustomParameter("FolderId", FolderId.ToString());
folderparameter.Type = TypeCode.String;
TempGalleryDataSource.Parameters.Add(folderparameter);
Gallery.Visible = true;
Gallery.DataBind();
}
}
}
***********************************************
foreach (Telerik.Web.UI.UploadedFile file in RadUpload1.UploadedFiles) is 0. so no files in postback???
ascx code:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UploadItemGalleryImage.ascx.cs" Inherits="IpitchitWeb.UserWebControls.UploadItemGalleryImage" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register Assembly="Microsoft.Web.GeneratedImage" Namespace="Microsoft.Web" TagPrefix="generatedImg" %>
<%@ Register Namespace="Microsoft.Web" TagPrefix="generatedImg" %>
<telerik:RadUpload ID="RadUpload1" runat="server"
MaxFileInputsCount="10" AllowedFileExtensions="gif, jpg, png"
MaxFileSize="5120000" OverwriteExistingFiles="True">
</telerik:RadUpload>
<telerik:RadProgressArea ID="RadProgressArea1" Runat="server">
</telerik:RadProgressArea>
<telerik:RadProgressManager ID="RadProgressManager1" Runat="server" />
<asp:Button ID="btnUploadFiles" runat="server" onclick="UploadFinished"
Text="Upload files to gallery" />
<telerik:RadAjaxPanel runat="server" ID="galleryPanel">
<div>
<asp:Label runat="server" ID="AlbumNameLabel" AssociatedControlID="AlbumName"></asp:Label>
<asp:TextBox runat="server" ID="AlbumName" Text='<%# AlbumTitle %>'></asp:TextBox>
</div>
<div>
<asp:Label runat="server" ID="AlbumDescriptionTitle" AssociatedControlID="AlbumDescriptionText">Album description:</asp:Label>
<asp:TextBox runat="server" ID="AlbumDescriptionText" Text='<%# AlbumDescription %>'></asp:TextBox>
</div>
<div>
<asp:Button runat="server" ID="btnSaveAlbumDetials" Text="Save album details" />
</div>
<asp:DataList runat="server" ID="Gallery" DataSourceID="TempGalleryDataSource" Visible="false">
<HeaderTemplate>
<div>Album</div>
</HeaderTemplate>
<ItemTemplate>
<div>
<asp:Label runat="server" ID="imageAlbumTitle"></asp:Label>
<generatedImg:GeneratedImage ImageHandlerUrl="~/Handlers/GetThumbnail.ashx" runat="server" AlternateText='<%# Eval("Filename") %>'>
<Parameters>
<generatedImg:ImageParameter Name="Width" Value="200" />
<generatedImg:ImageParameter Name="Height" Value="200" />
<generatedImg:ImageParameter Name="Path" Value='<%# Eval("Filename") %>' />
<generatedImg:ImageParameter Name="UseFileSystem" Value="False" />
<generatedImg:ImageParameter Name="CacheToServer" Value="True" />
<generatedImg:ImageParameter Name="CacheToClient" Value="True" />
</Parameters>
</generatedImg:GeneratedImage>
<div>
<span>Main item image:</span>
<asp:LinkButton runat="server" CommandName="MakeFrontImage" CommandArgument='<%# Eval("ImageId") %>'></asp:LinkButton>
</div>
</div>
</ItemTemplate>
</asp:DataList>
<asp:Button runat="server" ID="btnUpdateGalleryImage" Text="Update Gallery" />
</telerik:RadAjaxPanel>
<data:TempGalleriesDataSource runat="server" ID="TempGalleryDataSource"
EnableCaching="false" EnablePaging="false" SelectMethod="GetByFolderId">
<Parameters>
<%--<data:CustomParameter Name="FolderId" Type="Int32" Value='<%# FolderId %>' />--%>
</Parameters>
</data:TempGalleriesDataSource>
codebehind:
namespace IpitchitWeb.UserWebControls
{
public partial class UploadItemGalleryImage : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
//Ipitchit.Data.DataRepository.OriginalImagesProvider.GetAll()
}
private string storePath;
/// <summary>
/// Virtual path for temp folder and that doesn't include Galleries path. Creates folder if it doesn't exist.
/// </summary>
public String StorePath
{
get { return storePath; }
set {
storePath = value;
storePath = Ipitchit.Helper.ImageProcessing.ConvertToServerPath(storePath);
string syspath = storePath + "\\Galleries";
RadUpload1.TargetPhysicalFolder = syspath;
if (!System.IO.Directory.Exists(syspath))
{
try
{
System.IO.Directory.CreateDirectory(syspath);
}
catch (System.Exception ex)
{
throw ex;
}
}
RadUpload1.TargetPhysicalFolder = syspath;
}
}
public int Width { get; set; }
public int Height { get; set; }
private Guid folderId;
public Guid FolderId
{
get
{
if (ViewState["folderId"] != null)
{
folderId = new Guid(ViewState["folderId"].ToString());
}
return folderId;
}
set {
folderId = value;
ViewState["folderId"] = folderId.ToString();
}
}
public string AlbumTitle { get; set; }
public string AlbumDescription { get; set; }
protected void UploadFinished(object sender, EventArgs e)
{
//upload finished.. ready to save files to folders.
// Galeries folder is tempfolder + \Galleries
string SavePath = Server.MapPath(storePath + "/Galleries/");
//TempFolders savelocation = DataRepository.TempFoldersProvider.GetByFolderid(FolderId);
//we know where we will save files.. now we must save them and rezise them correctly.
foreach (Telerik.Web.UI.UploadedFile file in RadUpload1.UploadedFiles)
{
string filename = SavePath + Guid.NewGuid().ToString() + "." + file.GetExtension();
int Width = 600;
int Height = 600;
//saving temp image to database.
var originalImage = new OriginalImages();
Ipitchit.Helper.ImageTransformInfo transformation = Ipitchit.Helper.ImageProcessing.SaveImageAsResized(filename, file.InputStream, Width, Height);
originalImage.Size = transformation.OriginalImage.ImageByteBuffer.Length;
originalImage.Width = transformation.OriginalImage.Image.Width;
originalImage.Height = transformation.OriginalImage.Image.Height;
originalImage.StorageWidth = transformation.ResizedImage.Image.Width;
originalImage.StorageWidth = transformation.ResizedImage.Image.Height;
originalImage.Uploader = this.Page.User.Identity.Name;
originalImage.Created = DateTime.Now;
originalImage.Filename = filename;
originalImage.Alt = AlbumTitle;
originalImage.AlbumTitle = AlbumTitle;
originalImage.AlbumDescription = AlbumDescription;
originalImage.AlbumOrder = 0;
DataRepository.OriginalImagesProvider.Insert(originalImage);
//saving gallery..
var tempgallery = new TempGalleries();
tempgallery.FolderId = this.FolderId;
tempgallery.CreatedDate = DateTime.Now;
tempgallery.ValidDate = DateTime.Now.AddHours(1);
tempgallery.IsFront = false;
tempgallery.ImageId = originalImage.ImageId;
DataRepository.TempGalleriesProvider.Insert(tempgallery);
}
var folderparameter = new Ipitchit.Web.Data.CustomParameter("FolderId", FolderId.ToString());
folderparameter.Type = TypeCode.String;
TempGalleryDataSource.Parameters.Add(folderparameter);
Gallery.Visible = true;
Gallery.DataBind();
}
}
}
***********************************************
foreach (Telerik.Web.UI.UploadedFile file in RadUpload1.UploadedFiles) is 0. so no files in postback???