I have a VB console application.
I would like to get the absolute URL of the page.
Here is my current code:
Using siteCollectSPSite As New SPSite("http://mySite")
Dim blogPostSpList As SPList
'Get only the subsite of <locale/blogs>
Using blogSiteSPWeb As SPWeb = siteCollectSPSite.OpenWeb("/blogs")
For Each subsite As SPWeb In blogSiteSPWeb.Webs
Console.WriteLine("Subsite title: " & subsite.Url)
'......
Next
Right now, what I get is: http://mySite/blogs/myblog1
What I want to get is the full URL: http://mySite/blogs/myblog1/default.aspx
How can I get the "default.aspx"?
WelcomePage is the property of SPFolder type so to get the full url , you have to use :
subsite.Url + "/" + subsite.RootFolder.WelcomePage;
SPFolder.WelcomePage should have worked. If it didn't you need to set the "vti_welcomepage" in the properties of the Folder list item. This is what MS does under the hood.
if (this.m_strRedirectUrl == null)
{
string text = (string)this.Properties["vti_welcomepage"];
if (text == null)
{
text = string.Empty;
}
this.m_strRedirectUrl = text;
}
return this.m_strRedirectUrl;
Ok so your problem is that SPWeb doesnt actually have a 'page' as such. Default.aspx is simply one page inside the SPWeb container.
You can modify/read the default page using publishingWeb if you have the publishing feature enabled otherwise try this:
http://curia.me/post/2011/05/20/SharePoint-how-change-the-default-page-of-a-SPWeb.aspx
Related
I'm automating a test of location selection. The options will be in the dropdown menu. There are three options(locations) in the dropdown menu. Depending on the location selected the data on the page will be changed accordingly. I'm trying to store the location in the properties and retrieve from it. The location in the properties file looks like:
location=UK
The code to retrieve the location property:
Properties prop = new Properties();
prop.load(f);
setLocation(prop.getProperty("location"));
When I try to print the location property, the correct value is getting displayed.
System.out.println(prop.getProperty("location")); //The value UK is displayed
The setLocation() method code is:
wait.until(ExpectedConditions.visibilityOf(selectLocation));
selectLocation.click(); //now the dropdown will be displayed
Actions action = new Actions(driver);
if(location == "UK") {
wait.until(ExpectedConditions.visibilityOf(ukLocation));
action.moveToElement(ukLocation).click().build().perform();
}
else if(location == "US") {
wait.until(ExpectedConditions.visibilityOf(usLocation));
action.moveToElement(usLocation).click().build().perform();
}else {
System.out.println("didn't get the location");
}
When I run the code
"didn't get the location"
is getting displayed.
I've implemented the properties for the URL and it worked. Here I can get the location property and display it on the console but the problem is occurring at the string comparison. The setLocation() method works if I pass string as the location like:
setLocation("UK");
Try using the .equals rather ==.
if(location.equals("UK")) {
I’m using SharePoint 2010 and InfoPath 2010 on IE 11, w/Windows 7 operating system.
I have an InfoPath form that I want the user to be able to fill in the data and have the option to download a copy (with the data), as a pdf or word document – save as feature.
I see in InfoPath filler (office 2010) I can perform this “save as PDF” function but not in SharePoint 2010. Is there a setting I’m missing or do I have to go the route of extending SharePoint foundation w/ASP.net?
Thanks
Sorry, there is no native SharePoint 2010 functionality that meets your requirements. But there are several 3rd party tools you can purchase, or, of course, follow your own suggestion and pursue custom options.
I created a shim for SP2010 that will cause all Infopath forms in a sharepoint 2010 site to download, as long as the link to the form is in Sharepoint 2010. You will need jquery 1.12 for this to run.
$(function() {
if (document.getElementsByTagName('BODY')[0].innerHTML.indexOf('.xsn') != -1) {
$('a[href$=".xsn"]').each(function(index) {
var self = $(this);
var fileLocation = '';
var spDownloadsUrl = '/_layouts/download.aspx?SourceUrl=';
//GRAB LINK'S HREF LINK PATH AND URI ENCODE IT
var currentUrl = encodeURI(self.attr('href'));
//IF THE HREF IS TO A NETWORK FILE LOCATION EXIT THE PROCESS AND LEAVE IT ALONE
if (currentUrl.indexOf('file:') != -1) {
return;
}
//SHAREPOINT 2010 DOC LIST ELEMENTS HAVE INLINE JS ALTERING THE LINK BEHAVIOR, SO THEY NEED TO BE REMOVED
self.removeAttr('onclick');
self.removeAttr('onmousedown');
self.removeAttr('onfocus');
//IF THE LINK'S URL IS ABSOLUTE PATH, BUILD IT AS RELATIVE
if (currentUrl.indexOf('.com') != -1) {
var urlSplitOnDotCom = currentUrl.split('.com');
var urlAfterDotCom = urlSplitOnDotCom[1];
var urlPartsArr = urlAfterDotCom.split('/');
//REBUILD URL FROM ARRAY
var newPathname = "";
for (i = 1; i < urlPartsArr.length; i++) {
newPathname += "/";
newPathname += urlPartsArr[i];
}
fileLocation = newPathname;
} else {
fileLocation = currentUrl;
}
//ADD NEW URL TO INFOPATH FILE'S HREF ATTRIBUTE
self.attr('href', spDownloadsUrl + fileLocation);
});
}
});
I am working on an MVC 4 web application. On one page I am providing an anchor link which refers to a file on application's directory. The code of the same is -
#Html.Action("Download_Static_File", "Charge_Entry", new { File_Path = "../../Content/Templates/Pt_Data/Pt_Data.xls", File_Name = "Pt_Data_Template", value = "Download template" });
My motive is that the file should be downloaded on click.
However when I click the link, I get an error like
Could not find a part of the path 'C:\Program Files\Common Files\Microsoft Shared\Content\Templates\Pt_Data\Pt_Data.xls'.'
I also tried
System.Web.HttpContext.Current.Server.MapPath
which is giving this error:
OutputStream is not available when a custom TextWriter is used.
The action method being called is:
public FileResult Download_Static_File(string File_Path,string File_Name)
{
byte[] fileBytes = System.IO.File.ReadAllBytes(File_Path);
return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, File_Name);
}
Is it the correct approach? Any help will be appreciated.
I also referred this link
Your anchor seem to be pointing to a controller action named Download_Static_File (which unfortunately you haven't shown) and passing a parameter called File_Path.
The #Html.Action helper that you are using in your view is attempting to execute the specified action as a child action. You may find the following blog post useful which describes child actions: http://haacked.com/archive/2009/11/18/aspnetmvc2-render-action.aspx/
I guess that what you are trying to achieve is to generate an anchor in your view pointing to the static file which can be downloaded by the user. In this case you'd rather use an anchor tag in conjunction with the Url.Action helper:
<a href="#Url.Content("~/Content/Templates/Pt_Data/Pt_Data.xls")">
Download_Static_File
</a>
This assumes that your web application has a folder called Content/Templates/Pt_Data under the root containing a file named Pt_Data.xls which will be downloaded by the user when he clicks upon this anchor tag.
If on the other hand the file that you want to be downloaded by the user is situated in a folder which is not publicly accessible from the client (for example the ~/App_Data folder) you might in this case have a controller action on your server that will stream the file:
public ActionResult DownloadStaticFile(string filename)
{
string path = Server.MapPath("~/App_Data");
string file = Path.Combine(path, filename);
file = Path.GetFullPath(file);
if (!file.StartsWith(path))
{
throw new HttpException(403, "Forbidden");
}
return File(file, "application/pdf");
}
and then in your view you would have an anchor to this controller action:
#Html.ActionLink(
linkText: "Download template",
actionName: "DownloadStaticFile",
controllerName: "Charge_Entry",
routeValues: new { filename = "Pt_Data.xls" },
htmlAttributes: null
)
I'm currently writing a site using Sitefinity CMS. Can someone please explain how to get the current dynamic content item from server side code on page_load?
I have written a user control to display a custom gallery of sliding images. There are multiple content types in my dynamic module. The user control will sit as part of the masterpage template rather than on every page. On each page load I would like to fetch the current dynamiccontent item that is associated with the page and examine whether it has a property with the name 'Gallery'. If so I would then extract the images and render them via the usercontrol.
Thanks,
Brian.
I'm assuming your images are related content. This gets every published content item of your type.
var dynamicModuleManager = DynamicModuleManager.GetManager();
var moduleType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.YOURTYPEHERE");
var dcItems = dynamicModuleManager.GetDataItems(moduleType)
.Where(l => l.Status == ContentLifecycleStatus.Master);
foreach (var dcItem in dcItems)
{
//pass the dynamic content item to a model constructor or populate here, then
// get your image this way:
var image = dcItem.GetRelatedItems<Image>("Images").SingleOrDefault();
if (image != null)
{
ImageUrl = image.MediaUrl;
}
}
I am trying to create a custom link from sitecore into my view
#Html.Sitecore().Field("CTA display", Model.Item, new { text = "<span>" + + "</span>"})
I am not 100% sure what the correct way to do this is, but I want to wrap the text from the link into a for styling. I've tried to put the Model.Rendering.Item.Fields["CTA display"] into there with .Text and it doesn't work.
Any help would be appreciated.
First, I'd start by creating a SitecoreHelper extension method that allows you to modify the inner html of the element you're rendering:
public static HtmlString Field(this SitecoreHelper helper, string fieldName, Item item, object parameters, string innerHtml)
{
if (helper == null)
{
throw new ArgumentNullException("helper");
}
if (innerHtml.IsNullOrEmpty())
{
return helper.Field(fieldName, item, parameters);
}
return new HtmlString(helper.BeginField(fieldName, item, parameters).ToString() + innerHtml + helper.EndField().ToString());
}
This will allow you to pass an optional innerHtml string that will be inserted between opening and closing tags of your element (in this case, an <a> tag).
From here, pass your html string containing your CTA label to the above method, or modify the method to output the field's Text value wrapped in a <span>.
I used the solution posted above by computerjules which worked a treat. You can then called the extended method like follows
#Html.Sitecore().Field("Link", Html.Sitecore().CurrentItem, new {Class = "some-class"}, "<span class='some-other-class'></span>")
and the span is rendered within the anchor tabs