Note that there are some explanatory texts on larger screens.

plurals
  1. POtrim string after number
    text
    copied!<p>i need to adjust my code so that it will trim the url after the number. for example, i want everything after List=36 removed. letters and special characters are the only potential characters that could follow the List number. so i just want to trim the url when it reads a letter or special character after the list number. thanks. </p> <p>examples of current urls that are capture on submit</p> <pre><code>https://portal.test/sites/test/testabc/Lists/TEST/DispFormSort.aspx?List=36caab7e%2D2234%2D4981%2D8225%%2Easpx https://portal.test/sites/test/testabc/Lists/TEST/DispFormSort.aspx?List=36,http://portal.test/testabc/Lists/TEST/AllItems.aspx </code></pre> <p>url i want captured on submit:</p> <p><a href="https://portal.test.com/sites/test/testabc/Lists/RFC/DispFormSort.aspx?List=36" rel="nofollow">https://portal.test.com/sites/test/testabc/Lists/RFC/DispFormSort.aspx?List=36</a></p> <p>my current code for the method that captures the url:</p> <pre><code> public static string GenerateShortUrl(SPList list, int itemId) { try { var item = list.GetItemById(itemId); var itemUrl = string.Empty; if (item.File == null) itemUrl = SPContext.Current.Web.Url + "/" + list.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url + "?ID=" + item.ID; else itemUrl = SPContext.Current.Web.Url + "/" + item.Url; var generatedShortedUrl = GetShortUrl(itemUrl); return generatedShortedUrl; } catch (Exception ex) { Utilities.WriteError(ex.ToString()); throw new SPException("An error occurred while attempting to shorten a URL.", ex); } } </code></pre> <hr> <pre><code> private static string GetShortUrl(string itemUrl) { var shortId = Utilities.GenerateHash(itemUrl); var shortenerUrl = string.Empty; SPSecurity.RunWithElevatedPrivileges(delegate() { var farm = SPAdministrationWebApplication.Local; using (var site = farm.Sites[0]) { using (var web = site.RootWeb) { if (!web.Properties.ContainsKey("LiebrandUrlShortener")) throw new SPException(SPUtility.GetLocalizedString("$Resources:liebrandurlshortener,CannotFindUrl", "liebrandurlshortener", web.Language)); var urlList = web.Lists[SPUtility.GetLocalizedString("$Resources:liebrandurlshortener,StorageName", "liebrandurlshortener", web.Language)]; var query = new SPQuery(); query.Query = "&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name='Title'/&gt;&lt;Value Type='Text'&gt;" + shortId + "&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;"; var items = urlList.GetItems(query); if (items.Count == 0) { var urlListItem = urlList.Items.Add(); urlListItem["Title"] = shortId; urlListItem["RedirectTo"] = itemUrl; web.AllowUnsafeUpdates = true; urlListItem.Update(); web.AllowUnsafeUpdates = false; } shortenerUrl = web.Properties["LiebrandUrlShortener"]; } } }); return shortenerUrl + "/" + shortId; } public static string GenerateShortUrl(string longUrl) { return GetShortUrl(longUrl); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload