none
Discussion Forum storing Special Character in Title differently RRS feed

  • Question

  • I have this requirement where in I have to create a Custom web part which queries the two different discussion forums and display the title of those discussion forumn in the webpart, which on click should go the their respective discussion forum. I have created this webpart successfully. But the the issue now is because the site is in different language (Danish) the user can enter any character (special character too like { ', ?, , /, " etc} in the title. I have handled that too by incorporating Htmlencoding/decoding and regex. But the problem here is MOSS 2007 handle these special character differently when it stores the discussion thread. For example if I add a Discussion thread with title as "Testing? , /" and on site it store it like http://tempsite:1111/debate/Lists/Debat/Flat.aspx?RootFolder=%2fdebat%2fLists%2fDebat%2fTesting%20%2c&FolderCTID=<FolderContentIDHereRemoved>&TopicsView=<ViewURLHereRemoved>. I could see this when i click on the discussion. As you can see the difference(made BOLD). Now the problem when I'm rendering the url to the item on the webpart I am doing that on runtime (building the url in run time). I know there should be better way to do it, but would like to know how sharepoint handle the storage of these special character in Discussion Forum, as it seem they are using some other technique.

    Any pointer or direction would be really helpful to me.

    Regards & Thanks

    Paddy

    • Edited by Mike Walsh FIN Friday, February 25, 2011 8:41 AM Sharepoint : not needed in title and adds nothing
    Friday, February 25, 2011 7:14 AM

Answers

  • Paddy,

    Interesting issue.

    It seems that SharePoint will allow the Title of the discussion board to remain with the special characters, but the actual URL will not be allowed and will strip them from the final URL.  SharePoint Manager easily shows this, btw.

    So, there are probably many different ways to get what you are looking for, but one way could be to have a Linq query look for all Discussion Boards on a given site and then return the Title and the DefaultViewUrl, which the latter could then be prefixed by the SPWeb.Url to give you something like "Testing? , /" for the title and http://mysite/Lists/Testing/AllItems.aspx (assuming that is the actual default view) which you could then use as the final URL for your hyperlink in your web part.

    In the code snippet below you can see the Linq query (which I assumed from your post that you need to query to find the Discussion Boards) and a simple DataTable that you could then use to populate a repeater or you just omit the DataTable and enumerate the results from the query yourself:

     

     

    var linqResults = from list in oSPWeb.Lists.Cast<SPList>() where list.BaseTemplate == SPListTemplateType.DiscussionBoard select list;

     

     

    DataTable oDataTable = new DataTable();

     

     

    DataColumn oDataColumn_Title = new DataColumn("Title", typeof(string));

    oDataTable.Columns.Add(oDataColumn_Title);

     

     

    DataColumn oDataColumn_URL = new DataColumn("URL", typeof(string));

    oDataTable.Columns.Add(oDataColumn_URL);

     

     

    foreach (SPList oSPList in linqResults)

    {

     

     

    DataRow oDataRow = oDataTable.NewRow();

    oDataRow[

     

    "Title"] = oSPList.Title.ToString();

    oDataRow[

     

    "URL"] = oSPWeb.Url + oSPList.DefaultViewUrl.ToString();

    oDataTable.Rows.Add(oDataRow);

    }

    oDataTable.AcceptChanges();

     

    Hope this helps, if I am way off base let me know, will be glad to take a look at this again.


    Patrick Cole - MSFT
    • Marked as answer by Wayne Fan Thursday, March 17, 2011 3:30 AM
    Wednesday, March 9, 2011 7:15 PM

All replies

  • Hi paddy,

     

    Thanks for your question.

    Here is the summary issue as I understand.

    Scenario: there are two discussion in your site. Now, you have created a custom web part to show the discussions. But there are some special character during the process of inputting. You can handle the character using “HTMLEncoding” and regex, but the “?, /” characters will be transferred to “2f%” and so on.

     

    The characters will be encoding in the URL.  You can decode them using the “HttpUtility.UrlDecode()” method, and then validate it using regex.

     

    More information:

    http://msdn.microsoft.com/en-us/library/adwtk1fy.aspx

     

    Thanks,

    Wayne

    TechNet Subscriber Support in forum

    If you have any feedback on our support, please contact tngfb@microsoft.com

    Monday, February 28, 2011 5:51 AM
  • Hi Wayne,

    Thanks for your reply.

    If you see in my earlier question I have mentioned if I try to add "Testing? , /" as the title to the discussion thread, and once the thread is created and then if i go to the Discussion forumn and hover the title "Testing? , /", the title is not completely encoded and url only shows "%2fTesting%20%2c" (part of it). So I was wondering where the "?" and "/" is gone when the title is added to the discussion forum.

    I hope I have clearly mentioned my problem now. Thanks.

    Regards,

    Paddy

    Monday, February 28, 2011 1:37 PM
  • Hello Paddy74,
     
    Glad to receive your reply.

    I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.
     
    Thank you for your understanding and support.

    Thursday, March 3, 2011 7:20 AM
  • Thanks Wayne on taking this issue. Really looking forward to hear from you.

    Thanks & Regards,

    Paddy

    Friday, March 4, 2011 12:54 PM
  • Paddy,

    Interesting issue.

    It seems that SharePoint will allow the Title of the discussion board to remain with the special characters, but the actual URL will not be allowed and will strip them from the final URL.  SharePoint Manager easily shows this, btw.

    So, there are probably many different ways to get what you are looking for, but one way could be to have a Linq query look for all Discussion Boards on a given site and then return the Title and the DefaultViewUrl, which the latter could then be prefixed by the SPWeb.Url to give you something like "Testing? , /" for the title and http://mysite/Lists/Testing/AllItems.aspx (assuming that is the actual default view) which you could then use as the final URL for your hyperlink in your web part.

    In the code snippet below you can see the Linq query (which I assumed from your post that you need to query to find the Discussion Boards) and a simple DataTable that you could then use to populate a repeater or you just omit the DataTable and enumerate the results from the query yourself:

     

     

    var linqResults = from list in oSPWeb.Lists.Cast<SPList>() where list.BaseTemplate == SPListTemplateType.DiscussionBoard select list;

     

     

    DataTable oDataTable = new DataTable();

     

     

    DataColumn oDataColumn_Title = new DataColumn("Title", typeof(string));

    oDataTable.Columns.Add(oDataColumn_Title);

     

     

    DataColumn oDataColumn_URL = new DataColumn("URL", typeof(string));

    oDataTable.Columns.Add(oDataColumn_URL);

     

     

    foreach (SPList oSPList in linqResults)

    {

     

     

    DataRow oDataRow = oDataTable.NewRow();

    oDataRow[

     

    "Title"] = oSPList.Title.ToString();

    oDataRow[

     

    "URL"] = oSPWeb.Url + oSPList.DefaultViewUrl.ToString();

    oDataTable.Rows.Add(oDataRow);

    }

    oDataTable.AcceptChanges();

     

    Hope this helps, if I am way off base let me know, will be glad to take a look at this again.


    Patrick Cole - MSFT
    • Marked as answer by Wayne Fan Thursday, March 17, 2011 3:30 AM
    Wednesday, March 9, 2011 7:15 PM
  • Hi Paddy74,

    Would you please let us know how is your problem going? Is the suggestion helpful for your issue?

    If you need further assistance, please feel free to let us know.

    Thanks,

    Wayne

    TechNet Subscriber Support in forum

    If you have any feedback on our support, please contact tngfb@microsoft.com

    Tuesday, March 15, 2011 1:09 AM
  • Appologies for not responding. I was little away so couldn't reply. I will try what Pattrick suggested and let you know if that resolved the issue. Till than please bear with me.

    Thanks to all the responds.

    Regards,

    Paddy

    Thursday, March 17, 2011 4:49 AM