below it is my photo code i want to put (fileupload1 control) to the formview please what it the solution.
News.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.IO;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
namespace UploadImages
{
public partial class Default : System.Web.UI.Page
{
//Process the file selcected by the user
protected void btnsave_Click(object sender, EventArgs e)
{
lblFileContentType.Text = "";
lblFileSize.Text = "";
if (fileupload1.HasFile)
{
//Check for duplicate file name on server
if (Duplicate_File(fileupload1.FileName)) return;
//Check the file size to ensure that it does not exceed our 2MB size limt
long maxFileSize = 2100000;
long fileSize = fileupload1.PostedFile.ContentLength;
if (fileSize > maxFileSize)
{
lblMsg.Text = "وێنهکه ئهپلۆد نهبوو لهبهر ئهوهی قهبارهکهی له 2 مێگا بایت زیاتره.";
return;
}
Upload_File();
}
else
{
lblMsg.Text = "وێنهکه دهست نیشان بکه !";
}
}
protected void Upload_File()
{
//check file type then save the file to the web server if eligible
if (CheckFileType(fileupload1.FileName))
{
string filename = Path.GetFileName(fileupload1.PostedFile.FileName);
fileupload1.SaveAs(Server.MapPath("../App_Othere/Upload/Wena/" + filename));
//Display confirmation message and file stats
lblMsg.Text = "وێنهکه ئهپلۆد بوو بهسهرکهوتوی.";
lblFileContentType.Text = "File type: " + fileupload1.PostedFile.ContentType;
int intContentLength = (fileupload1.PostedFile.ContentLength / 1024);
lblFileSize.Text = "File size: " + intContentLength.ToString() + "Kb";
TextBox3.Text = ("../App_Othere/Upload/Wena/") + fileupload1.FileName;
}
else
{
lblMsg.Text = "وێنهکه ئهپلۆد نهبوو !" +
"لهبهر ئهوهی وێنکه لهجۆری .gif, .png, .jpg .jpeg نهبوو.";
}
}
//Check file type selected by the user
protected bool CheckFileType(string filename)
{
string strFileExt = Path.GetExtension(filename);
switch (strFileExt.ToLower())
{
case ".gif":
return true;
case ".png":
return true;
case ".jpg":
return true;
case ".jpeg":
return true;
default:
return false;
}
}
//Determine if file name already exists in the Images folder
protected bool Duplicate_File(string filename)
{
if (System.IO.File.Exists(Server.MapPath("../App_Othere/Upload/Wena/") + fileupload1.FileName))
{
lblMsg.Text = "ههمان ناو پێشتر ئهپلۆد کراوه تکایهناوهکهی بگۆڕه !";
return true;
}
return false;
}
}
}
peshangm
Member
73 Points
137 Posts
FindControl on the FormView to get access to the control ?
May 03, 2012 04:27 PM|LINK
dear all
below it is my photo code i want to put (fileupload1 control) to the formview please what it the solution.
News.aspx.cs
using System; using System.Collections; using System.Configuration; using System.Data; using System.IO; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; namespace UploadImages { public partial class Default : System.Web.UI.Page { //Process the file selcected by the user protected void btnsave_Click(object sender, EventArgs e) { lblFileContentType.Text = ""; lblFileSize.Text = ""; if (fileupload1.HasFile) { //Check for duplicate file name on server if (Duplicate_File(fileupload1.FileName)) return; //Check the file size to ensure that it does not exceed our 2MB size limt long maxFileSize = 2100000; long fileSize = fileupload1.PostedFile.ContentLength; if (fileSize > maxFileSize) { lblMsg.Text = "وێنهکه ئهپلۆد نهبوو لهبهر ئهوهی قهبارهکهی له 2 مێگا بایت زیاتره."; return; } Upload_File(); } else { lblMsg.Text = "وێنهکه دهست نیشان بکه !"; } } protected void Upload_File() { //check file type then save the file to the web server if eligible if (CheckFileType(fileupload1.FileName)) { string filename = Path.GetFileName(fileupload1.PostedFile.FileName); fileupload1.SaveAs(Server.MapPath("../App_Othere/Upload/Wena/" + filename)); //Display confirmation message and file stats lblMsg.Text = "وێنهکه ئهپلۆد بوو بهسهرکهوتوی."; lblFileContentType.Text = "File type: " + fileupload1.PostedFile.ContentType; int intContentLength = (fileupload1.PostedFile.ContentLength / 1024); lblFileSize.Text = "File size: " + intContentLength.ToString() + "Kb"; TextBox3.Text = ("../App_Othere/Upload/Wena/") + fileupload1.FileName; } else { lblMsg.Text = "وێنهکه ئهپلۆد نهبوو !" + "لهبهر ئهوهی وێنکه لهجۆری .gif, .png, .jpg .jpeg نهبوو."; } } //Check file type selected by the user protected bool CheckFileType(string filename) { string strFileExt = Path.GetExtension(filename); switch (strFileExt.ToLower()) { case ".gif": return true; case ".png": return true; case ".jpg": return true; case ".jpeg": return true; default: return false; } } //Determine if file name already exists in the Images folder protected bool Duplicate_File(string filename) { if (System.IO.File.Exists(Server.MapPath("../App_Othere/Upload/Wena/") + fileupload1.FileName)) { lblMsg.Text = "ههمان ناو پێشتر ئهپلۆد کراوه تکایهناوهکهی بگۆڕه !"; return true; } return false; } } }News.aspx
<%@ Page Language="C#" Debug="true" ValidateRequest="false" MasterPageFile="~/ACP/Admin.master" CodeFile="News.aspx.cs" Inherits="UploadImages.Default" %> <%@ Register Assembly="CKEditor.NET" Namespace="CKEditor.NET" TagPrefix="CKEditor" %> <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <br /> <a href="../ACP/News-Edit.aspx"><span style="color: #0000ff; text-decoration: underline">بابهتهکان</span></a> <br /><br /> <div align="center"> <asp:FileUpload ID="fileupload1" runat="server" Width="231px" ToolTip="وێنهکه دهست نیشان بکه." /><br /> <br /> <asp:Button ID="btnsave" runat="server" Text="ئهپلۆد" onclick="btnsave_Click" ForeColor="White" BackColor="Green" Font-Bold="True"/> <br /> <asp:Label ID="lblMsg" runat="server" style="color: #FF0000;" /> <br /> <asp:Label id="lblFileContentType" runat="server" style="color: #000000;" /> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> <br /> <asp:Label id="lblFileSize" runat="server" style="color: #000000;" /> </div> <asp:FormView ID="FormView1" runat="server" CellPadding="4" DataKeyNames="articleID" DataSourceID="ObjectDataSourceNewNews" DefaultMode="Insert" ForeColor="#333333" Width="100%" HeaderText="زیادكردنی ههواڵی نوێ"> <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" /> <RowStyle BackColor="#E3EAEB" /> <InsertItemTemplate> سهردێڕ: <br /> <asp:TextBox ID="headlineTextBox" runat="server" Text='<%# Bind("headline") %>' Width="80%"></asp:TextBox><br /> بهشی ههوڵهكان: <br /> <asp:DropDownList Width="30%" ID="DropDownList1" Runat="server" DataSourceID="ObjectDataSourceCats" DataTextField="catName" DataValueField="catID" SelectedValue='<%# Bind("catID") %>'> </asp:DropDownList> <asp:ObjectDataSource ID="ObjectDataSourceCats" runat="server" DeleteMethod="Delete" OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" TypeName="AdminTableAdapters.News_CategoriesTableAdapter" UpdateMethod="Update" InsertMethod="Insert"> <DeleteParameters> <asp:Parameter Name="Original_catID" Type="Int32" /> </DeleteParameters> <InsertParameters> <asp:Parameter Name="catName" Type="String" /> <asp:Parameter Name="orderView" Type="Int32" /> </InsertParameters> <UpdateParameters> <asp:Parameter Name="catName" Type="String" /> <asp:Parameter Name="orderView" Type="Int32" /> <asp:Parameter Name="Original_catID" Type="Int32" /> </UpdateParameters> </asp:ObjectDataSource> <br /> ڕوخسهت: <br /> <asp:DropDownList ID="DropDownList2" runat="server" SelectedValue='<%# Bind("Perm") %>' Width="30%"> <asp:ListItem Value="1">دهركهوتن</asp:ListItem> <asp:ListItem Value="0">دهرنهكهوتن</asp:ListItem> </asp:DropDownList><br /> وێنهی بچوک <br /> <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("HomeText") %>' Width="90%"></asp:TextBox><br /> وێنهی گهوره: <br /> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("pic") %>' Width="90%"></asp:TextBox> <br /> کورته: <br /> <CKEditor:CKEditorControl ID="CKEditorControl2" BasePath="../App_Othere/ckeditor" runat="server" Text='<%# Bind("summary") %>' Width="" Height="300px"></CKEditor:CKEditorControl> درێژه: <br /> <CKEditor:CKEditorControl ID="CKEditorControl1" BasePath="../App_Othere/ckeditor" runat="server" Text='<%# Bind("fullStory") %>' Width="" Height="600px"></CKEditor:CKEditorControl> <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert"></asp:LinkButton> <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton> </InsertItemTemplate> <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" /> <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" /> <EditRowStyle BackColor="#7C6F57" /> <InsertRowStyle HorizontalAlign="Right" VerticalAlign="Middle" /> </asp:FormView> <asp:ObjectDataSource ID="ObjectDataSourceNewNews" runat="server" InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" SelectMethod="GetDataArticles" TypeName="AdminTableAdapters.News_ArticlesTableAdapter" DeleteMethod="Delete" UpdateMethod="Update"> <DeleteParameters> <asp:Parameter Name="Original_articleID" Type="Int32" /> </DeleteParameters> <InsertParameters> <asp:Parameter Name="headline" Type="String" /> <asp:Parameter Name="publishDate" Type="DateTime" /> <asp:Parameter Name="catID" Type="Int32" /> <asp:Parameter Name="summary" Type="String" /> <asp:Parameter Name="fullStory" Type="String" /> <asp:Parameter Name="Hit" Type="Int32" /> <asp:Parameter Name="Perm" Type="Int32" /> <asp:Parameter Name="Pic" Type="String" /> <asp:Parameter Name="HomeText" Type="String" /> </InsertParameters> <UpdateParameters> <asp:Parameter Name="Headline" Type="String" /> <asp:Parameter Name="PublishDate" Type="DateTime" /> <asp:Parameter Name="CatID" Type="Int32" /> <asp:Parameter Name="Summary" Type="String" /> <asp:Parameter Name="FullStory" Type="String" /> <asp:Parameter Name="Hit" Type="Int32" /> <asp:Parameter Name="Perm" Type="Int32" /> <asp:Parameter Name="Pic" Type="String" /> <asp:Parameter Name="HomeText" Type="String" /> <asp:Parameter Name="Original_articleID" Type="Int32" /> </UpdateParameters> </asp:ObjectDataSource> </asp:Content>Suly Web For It Solution.
asp.netx.0lo...
Member
362 Points
71 Posts
Re: FindControl on the FormView to get access to the control ?
May 07, 2012 06:38 AM|LINK
I don't quite understand where you want to refer to FileUpload control?
May you give me more details you want?
peshangm
Member
73 Points
137 Posts
Re: FindControl on the FormView to get access to the control ?
May 07, 2012 03:37 PM|LINK
i want put FileUpload control below DropDownList control
Suly Web For It Solution.
peshangm
Member
73 Points
137 Posts
Re: FindControl on the FormView to get access to the control ?
May 10, 2012 09:30 AM|LINK
some one help me to find this control.
Suly Web For It Solution.
peshangm
Member
73 Points
137 Posts
Re: FindControl on the FormView to get access to the control ?
Oct 25, 2012 09:52 PM|LINK
it is solved by FindControl way
Suly Web For It Solution.