using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Web.DynamicData;
public partial class FileField : System.Web.DynamicData.FieldTemplateUserControl
{
protected override void OnDataBinding(EventArgs e)
{
base.OnDataBinding(e);
if (!String.IsNullOrEmpty(FieldValueString))
{
var metadata = MetadataAttributes.OfType<FileAttribute>().FirstOrDefault();
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Web.DynamicData;
using System.IO;
public partial class File_EditField : System.Web.DynamicData.FieldTemplateUserControl
{
protected override void OnDataBinding(EventArgs e)
{
base.OnDataBinding(e);
if (!String.IsNullOrEmpty(FieldValueString))
{
string fileAttributePath = GetFileAttributePath();
one thing else .. how to display file name or file icon next to file upload control .. so that i can see it in edit mode and in display mode(grid view)
Member
18 Points
153 Posts
Custom Delete
Feb 18, 2012 06:19 AM|tamer el morsi|LINK
Hey all;
i have this table "Projects" with fields
ProjectId,
CityId,
ProjectTitle,
Photo....
now i want to clear photo field for specfic record in my table..
but the delete button would delete the entire record .
so any idea on how to add delete button for the photo field???
Star
14742 Points
3114 Posts
Re: Custom Delete
Feb 18, 2012 07:51 AM|adeelehsan|LINK
You can set it to null using the following query:
Above is just a sample query, you have to pass corresponding project id to set its photo to null.
MCSD[ASP.NET 4.5, SharePoint 2013], MCTS [WSS 3.0, MOSS 2007, SharePoint 2010], MCT
Microsoft Community Contributor Award 2011
Member
18 Points
153 Posts
Re: Custom Delete
Feb 18, 2012 02:05 PM|tamer el morsi|LINK
how to do it in dynamicdata page ... not in sql
All-Star
17916 Points
5681 Posts
MVP
Re: Custom Delete
Feb 18, 2012 06:43 PM|sjnaughton|LINK
you need to add a button to your field template that setts the
and is you store the fiel on disk also delete the file.
Always seeking an elegant solution.
Member
18 Points
153 Posts
Re: Custom Delete
Feb 19, 2012 07:22 AM|tamer el morsi|LINK
can you give steps on how to code this button ...
also how to pass file name so i can delete it??
All-Star
17916 Points
5681 Posts
MVP
Re: Custom Delete
Feb 19, 2012 11:11 AM|sjnaughton|LINK
What file upload field template are you using?
Always seeking an elegant solution.
Member
18 Points
153 Posts
Re: Custom Delete
Feb 19, 2012 11:58 AM|tamer el morsi|LINK
File.ascx and File_Edit.ascx ...... the default ones
All-Star
17916 Points
5681 Posts
MVP
Re: Custom Delete
Feb 19, 2012 12:12 PM|sjnaughton|LINK
There is no default File upload fiel;d template, where did you get it, coudl you post the code and markup then I can modify that and post back.
Always seeking an elegant solution.
Member
18 Points
153 Posts
Re: Custom Delete
Feb 19, 2012 12:36 PM|tamer el morsi|LINK
File.ascx
<%@ Control Language="C#" CodeFile="File.ascx.cs" Inherits="FileField" %>
<asp:HyperLink ID="HyperLink1" Visible="false" Target="_blank" runat="server">Download</asp:HyperLink>
File.ascx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Web.DynamicData;
public partial class FileField : System.Web.DynamicData.FieldTemplateUserControl
{
protected override void OnDataBinding(EventArgs e)
{
base.OnDataBinding(e);
if (!String.IsNullOrEmpty(FieldValueString))
{
var metadata = MetadataAttributes.OfType<FileAttribute>().FirstOrDefault();
if (metadata != null)
{
HyperLink1.NavigateUrl = Utility.FrontendVirtualPath + metadata.Path + FieldValueString;
HyperLink1.Visible = true;
}
}
}
public override Control DataControl
{
get
{
return HyperLink1;
}
}
}
File_Edit.ascx
<%@ Control Language="C#" CodeFile="File_Edit.ascx.cs" Inherits="File_EditField" %>
<asp:HyperLink ID="HyperLink1" Visible="false" Target="_blank" runat="server">Download</asp:HyperLink>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1" CssClass="droplist"
ControlToValidate="FileUpload1" Display="Dynamic" Enabled="false" />
<asp:RegularExpressionValidator runat="server" ID="RegularExpressionValidator1" CssClass="droplist"
ControlToValidate="FileUpload1" Display="Dynamic" Enabled="false" />
<asp:DynamicValidator runat="server" ID="DynamicValidator1" CssClass="droplist" ControlToValidate="FileUpload1"
Display="Dynamic" />
File_Edit.ascx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Web.DynamicData;
using System.IO;
public partial class File_EditField : System.Web.DynamicData.FieldTemplateUserControl
{
protected override void OnDataBinding(EventArgs e)
{
base.OnDataBinding(e);
if (!String.IsNullOrEmpty(FieldValueString))
{
string fileAttributePath = GetFileAttributePath();
HyperLink1.NavigateUrl = Utility.FrontendVirtualPath + fileAttributePath + FieldValueString;
HyperLink1.Visible = true;
}
else
{
SetUpValidator(RequiredFieldValidator1);
}
ViewState["FieldValueString"] = FieldValueString;
SetUpValidator(RegularExpressionValidator1);
SetUpValidator(DynamicValidator1);
}
protected override void ExtractValues(IOrderedDictionary dictionary)
{
if (FileUpload1.HasFile)
{
string fileAttributeFullPath = Utility.FrontendPhysicalPath + GetFileAttributePath();
string fileName = Utility.GetRand() + "-" + FileUpload1.FileName;
FileUpload1.SaveAs(fileAttributeFullPath + fileName);
if (!String.IsNullOrEmpty(ViewState["FieldValueString"].ToString()))
try
{
File.Delete(fileAttributeFullPath + ViewState["FieldValueString"].ToString());
}
catch { }
dictionary[Column.Name] = fileName;
}
}
public override Control DataControl
{
get
{
return FileUpload1;
}
}
private string GetFileAttributePath()
{
var metadata = MetadataAttributes.OfType<FileAttribute>().FirstOrDefault();
if (metadata != null)
return metadata.Path;
else
return String.Empty;
}
}
All-Star
17916 Points
5681 Posts
MVP
Re: Custom Delete
Feb 19, 2012 01:06 PM|sjnaughton|LINK
OK I woudl add a checkbox to the Field_Edit.ascx file
then in the ExtractValues method check the checkbox if set set the dictionary to null this will null the value
give that a try.
Always seeking an elegant solution.
Member
18 Points
153 Posts
Re: Custom Delete
Feb 19, 2012 01:51 PM|tamer el morsi|LINK
thanks it works fine ..
one thing else .. how to display file name or file icon next to file upload control .. so that i can see it in edit mode and in display mode(grid view)
All-Star
17916 Points
5681 Posts
MVP
Re: Custom Delete
Feb 19, 2012 02:20 PM|sjnaughton|LINK
do you mean a file type icon?
Always seeking an elegant solution.
Member
18 Points
153 Posts
Re: Custom Delete
Feb 19, 2012 02:54 PM|tamer el morsi|LINK
what i mean is that in the display mode (gridview) i only see "Download" word but don't see file name or any icon about it...
also in edit mode i see the "FileUpload" control with empty string ...
so i need to tell users that there is a file already uploaded (if exist)
All-Star
17916 Points
5681 Posts
MVP
Re: Custom Delete
Feb 19, 2012 06:44 PM|sjnaughton|LINK
Then change the field template to use the FiedlValueString instead of the word Download.
Always seeking an elegant solution.
Member
18 Points
153 Posts
Re: Custom Delete
Feb 20, 2012 12:13 PM|tamer el morsi|LINK
how to display file type icon??
All-Star
17916 Points
5681 Posts
MVP
Re: Custom Delete
Feb 20, 2012 12:35 PM|sjnaughton|LINK
I would just add an image control and then have a set of jpegs named like this
png.jpeg
gif.jpeg
jpeg.jpeg
etc.
then set the image to the one that matches the file extension.
Always seeking an elegant solution.
None
0 Points
20 Posts
Re: Custom Delete
Feb 22, 2012 11:47 PM|Oscar Gomez|LINK
Hi,
It worked for me, thanks.
___________________
Oscar Gómez
Engineer at PSL
http://www.pslcorp.com/