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();
tamer el mor...
Member
63 Points
162 Posts
Custom Delete
Feb 18, 2012 10:19 AM|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???
adeelehsan
All-Star
18221 Points
2724 Posts
Re: Custom Delete
Feb 18, 2012 11:51 AM|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.
MCPD ASP.NET 4.0 and 3.5, MCTS WSS, MOSS, SharePoint 2010, MCT
Microsoft Community Contributor Award 2011
tamer el mor...
Member
63 Points
162 Posts
Re: Custom Delete
Feb 18, 2012 06:05 PM|LINK
how to do it in dynamicdata page ... not in sql
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: Custom Delete
Feb 18, 2012 10:43 PM|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.
tamer el mor...
Member
63 Points
162 Posts
Re: Custom Delete
Feb 19, 2012 11:22 AM|LINK
can you give steps on how to code this button ...
also how to pass file name so i can delete it??
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: Custom Delete
Feb 19, 2012 03:11 PM|LINK
What file upload field template are you using?
Always seeking an elegant solution.
tamer el mor...
Member
63 Points
162 Posts
Re: Custom Delete
Feb 19, 2012 03:58 PM|LINK
File.ascx and File_Edit.ascx ...... the default ones
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: Custom Delete
Feb 19, 2012 04:12 PM|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.
tamer el mor...
Member
63 Points
162 Posts
Re: Custom Delete
Feb 19, 2012 04:36 PM|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;
}
}
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: Custom Delete
Feb 19, 2012 05:06 PM|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.