>MWPSK
1. Problems with TagCloud when we don’t have Blog or Blog categories on our page.
Try to put TagCloud section without Blog or Categories (without entries) – there will be error.
That’s why we should add some code to few files – firs one is App_Code/Sctions/TagCloud.cs
private ArrayList Blogs
{
get
{
ArrayList blogs = new ArrayList();
//first one – when we dont have blog – exception DirectoryNotFound
try
{
//looks for all files in the blog folder
string[] files = Directory.GetFiles(HttpContext.Current.Server.MapPath("~/App_Data/Blog/"));
if (files.Length != 0)
{
for (int i = 0; i < files.Length; i++)
{
string id = files[i].Substring(files[i].LastIndexOf("\\") + 1);
id = id.Substring(0, id.LastIndexOf("."));
Blog blog = (Blog)Activator.CreateInstance(typeof(Blog), id);
blogs.Add(blog);
}
return blogs;
}
//
//
Else // error when we don’t have entries
{
return null;
}
}
catch (DirectoryNotFoundException ex)
{
return null;
}
}
}
When we change in this place we should also check null objects (same file):
public List<DataRow> TagsMerged()
{
if (!Object.Equals(Blogs, null))
{
List<DataRow> listTags = new List<DataRow>();
if (HttpContext.Current.Cache["TagCloudList"] != null)
{
listTags = (List<DataRow>)HttpContext.Current.Cache["TagCloudList"];
}
else
{
DataTable Tags = new DataTable("Tags");
ArrayList arrTagsStored = new ArrayList();
int intTagNumberTotal;
foreach (Blog blog in Blogs)
{
Tags.Merge(blog.BlogTags);
}
if (Tags.Rows.Count > 0)
{
for (int y = 0; y < Tags.Rows.Count; y++)
{
//check if the Tag has already been added to the generic list
if (!arrTagsStored.Contains(Tags.Rows[y]["Name"]))
{
intTagNumberTotal = 0;
DataRow[] rowsFound = Tags.Select(string.Format("Name = '{0}'", Tags.Rows[y]["Name"]));
for (int i = 0; i < rowsFound.Length; i++)
{
intTagNumberTotal += (int)rowsFound[i]["Number"];
}
if (intTagNumberTotal > 0)
{
Tags.Rows[y]["Number"] = intTagNumberTotal;
listTags.Add(Tags.Rows[y]);
arrTagsStored.Add(Tags.Rows[y]["Name"]);
}
}
}
}
//insert the data into the cache
HttpContext.Current.Cache.Insert("TagCloudList", listTags, null, DateTime.Now.AddMinutes(_cacheMinutes), System.Web.Caching.Cache.NoSlidingExpiration);
}
return listTags;
}
else
{
return null;
}
}
And in the same file:
public ChannelData GetSidebarRss(string PageId)
{
ChannelData elements = new ChannelData();
elements.Title = getCloudTitle();
List<DataRow> listTags = TagsMerged();
//sorting the TagCloud desc
//listTags.Sort(delegate(DataRow row1, DataRow row2)
// {
// return row2["Number"].ToString().CompareTo(row1["Number"].ToString());
// }
//);
if (!Object.Equals(listTags, null)) //here
{
int iPosition = 0;
foreach (DataRow row in listTags)
{
//show top 5 entries in Sidebar, or all in RSS Feed
if (!IsRenderedToSidebar() || iPosition < 5)
{
Dictionary<string, string> item = new Dictionary<string, string>();
foreach (string rsskey in Enum.GetNames(typeof(RssElements)))
{
insertRssKeyValue(rsskey, row, PageId, ref item);
}
elements.ChannelItems.Add(item);
}
if (IsRenderedToSidebar()) iPosition++;
}
return elements;
}
else
{
return null;
}
}
In App_Code/Controls/TagCloud.cs
public override void DataBind()
{
if (!Object.Equals(_dataSource, null))
{
List<TagCloudData> transferData = new List<TagCloudData>();
foreach (object obj in _dataSource)
{
if (obj.GetType() == typeof(DataRow))
{
DataRow row = (DataRow)obj;
transferData.Add(new TagCloudData(row["Name"].ToString(), (int)row["Number"]));
if (transferData[transferData.Count - 1].Instances < minInstances)
minInstances = transferData[transferData.Count - 1].Instances;
if (transferData[transferData.Count - 1].Instances > maxInstances)
maxInstances = transferData[transferData.Count - 1].Instances;
tagCount++;
}
else
throw new ArgumentException("Argument must contain only TagCloudData objects.", "DataSource");
}
finalizedData = transferData.ToArray();
_dataSource = null;
}
}
When we put TagCloud on sidebar we should change file App_Code/Sidebar.cs
public static bool GetSectionRss(XmlWriter rss, ISection section, string pageId, string TitlePrefix)
{
if (section != null)
{
ChannelData SectionChannel = ((ISidebarObject)section).GetSidebarRss(pageId);
if (!Object.Equals(SectionChannel, null)) //here
{
// In whatever namespace the sections are, extract only the typename for the Title Resource ID
string TypeName = section.GetType().ToString();
string[] arrTypeName = TypeName.Split('.');
string ResourceID = "ctl_" + arrTypeName[arrTypeName.GetLength(0) - 1] + "_RssTitle";
if (SectionChannel.Title == string.Empty)
SectionChannel.Title = Resources.StringsRes.ResourceManager.GetString(ResourceID);
if (TitlePrefix != string.Empty)
SectionChannel.Title = TitlePrefix + " " + SectionChannel.Title;
// generate feed and return wether items where found for this section
return SectionChannel.GetXml(ref rss);
}
else
{
return false;
}
}
else
{
return false;
}
}
2. Problems with saving data – mentioned few times on MWPSK (http://www.codeplex.com/MyWebPagesStarterKit/Thread/View.aspx?ThreadId=37407 or http://www.codeplex.com/MyWebPagesStarterKit/Thread/View.aspx?ThreadId=33230 or http://www.codeplex.com/MyWebPagesStarterKit/Thread/View.aspx?ThreadId=2745)
It’s not solution but only work around but works and solves al problems. Instead this code:
public void SaveData()
{
_path = HttpContext.Current.Server.MapPath(GetDataFilename());
lock (_path)
{
//insert the data into the cache
HttpContext.Current.Cache.Insert(_path, _data, null, DateTime.MaxValue, TimeSpan.FromHours(1), CacheItemPriority.Normal, null);
//if the given path does not exist yet, create it
if (!Directory.Exists(Path.GetDirectoryName(_path)))
Directory.CreateDirectory(Path.GetDirectoryName(_path));
//serialize and store the data to the filesystem
using (FileStream writer = File.Create(_path))
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
serializer.Serialize(writer, _data);
}
#region Changes made by Web-MA
// Changes to support lastMod change date
SiteMapNode smn = SiteMap.Provider.CurrentNode;
if (smn != null)
{
SitemapEditor editor = new SitemapEditor();
string path = smn.Url;
//Trim the path
if (path.Contains("?"))
path = path.Remove(path.IndexOf('?'));
editor.UpdateLastWriteTime(VirtualPathUtility.ToAppRelative(path, "/"));
editor.Save();
}
#endregion Changes made by Web-MA
}
}
Should be this one:
public void SaveData()
{
try
{
_path = HttpContext.Current.Server.MapPath(GetDataFilename());
lock (_path)
{
//insert the data into the cache
HttpContext.Current.Cache.Insert(_path, _data, null, DateTime.MaxValue, TimeSpan.FromHours(1), CacheItemPriority.Normal, null);
//if the given path does not exist yet, create it
if (!Directory.Exists(Path.GetDirectoryName(_path)))
Directory.CreateDirectory(Path.GetDirectoryName(_path));
//serialize and store the data to the filesystem
using (FileStream writer = File.Create(_path))
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
serializer.Serialize(writer, _data);
}
#region Changes made by Web-MA
// Changes to support lastMod change date
SiteMapNode smn = SiteMap.Provider.CurrentNode;
if (smn != null)
{
SitemapEditor editor = new SitemapEditor();
string path = smn.Url;
//Trim the path
if (path.Contains("?"))
path = path.Remove(path.IndexOf('?'));
editor.UpdateLastWriteTime(VirtualPathUtility.ToAppRelative(path, "/"));
editor.Save();
}
#endregion Changes made by Web-MA
}
}
catch (Exception ex)
{
}
}
3. ContactForm control – Thank You editor (FCK) is always English, instead this code:
protected void Page_Load(object sender, EventArgs e)
{
//Set the Default Langauge for the FCKEditor
string lang = System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
FCKeditorIntroText.DefaultLanguage = lang;
Should be:
protected void Page_Load(object sender, EventArgs e)
{
//Set the Default Langauge for the FCKEditor
string lang = System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
FCKeditorIntroText.DefaultLanguage = lang;
//Polish adatation - Artur
FCKeditorThankYouText.DefaultLanguage = lang;
4. Additional Themes
I gave you a lot of new themes to 1.1.4 version – see attached file (app_themes.zip) – I changed them to version 1.2.1 – it’s easy – on project website should be information how to upgrade:
In 1.1.4 we have:
<%@ Register TagPrefix="cc2" TagName="LoginStatus" Src="~/LoginStatus.ascx" %>
<%@ Register TagPrefix="cc2" TagName="Search" Src="~/SearchLink.ascx" %>
And
<div id="utilities"><cc2:LoginStatus runat="Server" id="LoginStatus1" /> <cc2:Search runat="Server" id="SearchLink1" /></div>
In 1.2.1 we should remove declaration and change utilities div to:
<div id="utilities"><cc1:LoginStatus runat="Server" id="LoginStatus1" /> <cc1:SearchLink runat="Server" id="SearchLink1" /></div>