IIS auto-generated webpage listing all websites being hosted - iis

Essentially what the title says. Is there a feature-of/addon-for IIS which allows presenting in a single web page a list with links pointing to the websites hosted within IIS?
I know I can get said list from the command line via:
%windir%\system32\inetsrv\appcmd list site > c:\sites.xls
This will then create an Excel spreadsheet with the list of sites in IIS + site related information for each site.
But then I will have to parse the CSV file and turn it into html. This would work, but I'ld rather dodge it altogether if there already is a feature or an addon for the exact same thing out there.

You can use Powershell for this: you can loop through IIS sites, virtual directories, web applications and dynamically build a simple html page.
Here is a simple script that creates an html file with a list of links to each virtual directory or web application. This is only a base script, you can customize it and add more details:
#Import WebAdministration to manage IIS contents
Import-Module WebAdministration
#define a variable that will hold your html code
$html = "<html>`n<body>"
#define the root path of your sites (in this example localhost)
$rootFolder = "http://localhost"
$Websites = Get-ChildItem IIS:\Sites
#loop on all websites inside IIS
foreach($Site in $Websites)
{
$VDirs = Get-WebVirtualDirectory -Site $Site.name
$WebApps = Get-WebApplication -Site $Site.name
#loop on all virtual directories
foreach ($vdir in $VDirs )
{
$html += "`n<a href='" + $rootFolder + $vdir.path +"'>" + $vdir.path + "</a><br/>"
}
#loop on all web applications
foreach ($WebApp in $WebApps)
{
$html += "`n<a href='" + $rootFolder + $WebApp.path +"'>" + $WebApp.path + "</a><br/>"
}
}
#add final tags to html
$html += "`n</body>`n</html>"
#write html code to file
$html >> "d:\sites.html"
For example with this IIS structure:
you get the following html:
<html>
<body>
<a href='http://localhost/vd'>/vd</a><br/>
<a href='http://localhost/test'>/test</a><br/>
<a href='http://localhost/test2'>/test2</a><br/>
</body>
</html>
that renders like this:

Related

How to get media url for each domain?

I am writing a plugin that works on the command line interface (CLI) and it pulls the URLs of images according to the APP_URL. The problem is that I need to set the media repository for each domain. The SalesChannelDomainId is defined on the $context parameter. On the frontend, the images are shown according to the domain name.
However, if I automatically add the SalesChannelDomain URL, it will cause a problem for CDN users. Should I write service for this?
$imageLinks = [];
$criteria = new Criteria($mediaIds);
$criteria->addAssociation('translations');
$medias = $this->mediaRepository->search($criteria, $context->getContext());
foreach ($medias as $media) {
$imageLinks[$media->getId()] = $media->getUrl();
}
$context has SalesChannelDomainId
Not sure if I understood your issue correctly but you may inject Shopware\Core\Content\Media\Pathname\UrlGeneratorInterface into your service and call getRelativeMediaUrl to get the relative path to the file. Then you can prepend the sales channel domains as you need them.
$relativePath = $this->urlGenerator->getRelativeMediaUrl($media);
$absolutePath = $salesChannel->getDomains()->first()->getUrl() . $relativePath;

How to add shortcut link in "Quick Access" in Windows 10 through code?

I want to add shortcut link of one of the folder location to "Quick Access" in windows 10.
In the case of Windows 7 & Windows 8, I used to put my shortcut link in the folder "C:\Users\user_name\Links" & it showed me shortcut in favorites at left side. So I want to do same thing for Windows 10.
I directly copy shortcut & pasted into the location of Quick Access. But still it's not showing in left panel of Quick Access.
As i know there are two option in Quick Access : 1. Frequent Folders & 2. Frequent Files.
So at what location do I need to put that shortcut link so it will appear in Quick Access section in left panel ?
And also I wanted to ask, how "OneDrive" link they have added in left panel in Windows 10 ? So is there any registry entry or any specific location ?
You can do it via this powershell script:
$o = new-object -com shell.application
$o.Namespace('c:\Folder').Self.InvokeVerb("pintohome")
I didn't found proper solution.
But I applied workaround for my problem.
I created folder at Quick Access location (\Links). And using mkilink cmd I changed the symbolic link of it to target folder. I used mklink using cmd prompt in C# code using Process.
I am using following code to create folder shortcut at c:\users\user_name\links and it is working fine in windows 7 & 8 but can't see it under windows 10 quick access link in windows explorer.
string sLinkFileName = "c:\users\user_name\links\\" + DefineString.AppName + ".lnk";
FileInfo objfiLinkFile = new FileInfo(sLinkFileName);
if (objfiLinkFile.Exists)
{
try
{
objfiLinkFile.Delete();
}
catch (Exception ex)
{
Logger.Log(LoggingLevel.Info, MethodBase.GetCurrentMethod().Name, string.Empty, ex);
}
}
//Place a shortcut to the file in the special folder
objfiLinkFile.Refresh();
if (objfiLinkFile.Exists)
{
Logger.Log(LoggingLevel.Info, MethodBase.GetCurrentMethod().Name, "Old link file still exists.");
}
// Create a shortcut in the special folder for the file
// Making use of the Windows Scripting Host
IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
IWshRuntimeLibrary.IWshShortcut link = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(objfiLinkFile.FullName);
link.TargetPath = Utils.msApplicationRootPath;
link.WindowStyle = 1;
link.Description = string.Format(DefineString.m00025, DefineString.AppName);
link.IconLocation = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\RootFolder.ico";
link.Save();
I also tried to call mklink as you mentioned; but it didn't work. Unfortunately we don't have any direct control over user desktop. mklink command requires admin privileges? Which mklink command you used to fix the issue. Your help will be greatly appreciated.
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = string.Format(#"/C mklink {0} {1}", sLinkFileName, Utils.msApplicationRootPath);
process.StartInfo = startInfo;
process.Start();

Sharepoint 2013 custom standard UI icons

i'm currently building up a design-solution-feature for SP13. it deploys master pages, layouts, css files etc.
my question is: is there actually any way to implement custom standard UI icons? e.g.: for the ribbonrow or settings icon on the top right corner?
it would be perfect if i could just overwrite the generated themedpng with a custom one (same dimensions of course) via code (event receiver).
Here are two ways to do it, but none of them is the perfect solution.
1- Backup "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\IMAGES\spcommon.png" and replace it with your own file.
This is not recommended because you should not touch SharePoint files.
It could be overwritten when installing a SharePoint update.
But it is an easy solution which is used sometimes in the real world.
2- You can use jquery (or javascript) to replace all references to "/_layouts/15/images/spcommon.png" by your own image once the page is loaded. You can deploy your image on your site.
Problem is the out of the box image will be displayed first and then replaced by your image. So there will be a very short time were the old image will be displayed.
this script included in the masterpage did it for me:
var CustomIcons = function () {
var site_url;
if (_spPageContextInfo.siteServerRelativeUrl === "/") {
site_url = "";
} else {
site_url = _spPageContextInfo.siteServerRelativeUrl;
}
var commom_img_url = site_url + '/_layouts/15/images/spcommon-custom.png';
var commom_img_url2 = site_url + '/_layouts/15/images/spcommon-custom2.png';
var help_img_url = site_url + '/_layouts/15/images/help.png';
var settings_img_url = site_url + '/_layouts/15/images/settings.png';
$('#siteactiontd').find('img:first').attr('src', settings_img_url);
$('#ms-help').find('img:first').attr('src', help_img_url);
$('#ctl00_SyncPromotedAction').find('img:first').attr('src', commom_img_url);
$('#ctl00_fullscreenmodeBtn').find('img:first').attr('src', commom_img_url);
$('a[_action="edit"]').find('img:first').attr('src', commom_img_url);
$('a[_action="save"]').find('img:first').attr('src', commom_img_url2);
}

How to get local file system path in azure websites

I have a file hosted on the disk along with my website that I want to read .Not sure how do I access the file when I use System.Environment.CurrentDirectory it point to a D drive location .Can someone please tell me how can I get to my file stored at the root of where my site is hosted.
Thanks
There is an environment variable called HOME in your website's environment that will get you part way there.
You can access it using razor syntax or in code (C#). For example, suppose you have a file called data.txt that is at the root of your site with the default document and the rest of your files. You could get it's full path like this.
#{ var dataFileName = Environment.GetEnvironmentVariable("HOME").ToString() + "\\site\\wwwroot\\data.txt"; }
You can find this out on your own using the Site Control Management/"Kudu". For example, if your website is contoso.azurewebsites.net, then simply navigate to contoso.scm.azurewebsites.net. In here you can learn all about the file system and environment variables available to your website.
For testability, I use below code.
string path = "";
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("HOME")))
path = Environment.GetEnvironmentVariable("HOME") + "\\site\\wwwroot\\bin";
else
path = ".";
path += "\\Resources\\myfile.json";
In above example, I added myfile.json file to Resources folder in a project with Content and Copy if newer property setting.
This works for me in both localhost and azure:
Path.Combine(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath, "file_at_root.txt");
System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath is the full local path to your site's root.
I'm currently using AppDomain.CurrentDomain.BaseDirectory (.NET Core project). It returns "D:\home\site\wwwroot\" in Azure and the application root in local so the only difference is adding "bin\\" when it is Azure. I am searching the entire directory tree, just in case, but it can be trimmed.
It's something like:
private static string GetDriverPath(ILogger logger, string fileName)
{
var path = AppDomain.CurrentDomain.BaseDirectory;
if (File.Exists(Path.Combine(path, fileName)))
{
return path;
}
string[] paths= Directory.GetFiles(path, fileName, SearchOption.AllDirectories);
if (paths.Any())
{
return Path.GetDirectoryName(paths.First());
}
throw new FileNotFoundException($"{fileName} was not found in {path}.", fileName);
}
I'm new answering questions and this is an old one but I hope it helps someone.
You can do it using the below code.
string fullFilePath = Environment.GetEnvironmentVariable("HOME") != null
? Environment.GetEnvironmentVariable("HOME") + #"\site\wwwroot\test.txt" //It will give the file directory path post azure deployment
: Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory())) + #"\test.txt";//It will give the file directory path in dev environment.

Is there a way to edit the HTML of multiple SharePoint 2013 pages at once?

You guys gotta save me.
I'm supposed to go into 70+ SharePoint 2013 pages and manually replace each of the 3+ links in the html of each page with the correct copied version. As in, all the links currently point toward /place1/place2/link and now they need to be /place3/place4/link
So, there has got to be a way to mass edit all of the pages, like a find and replace, because otherwise I'm just going to go sit in a corner and cry for hours. I can't edit the folder structure because I'm not the project leader.
I will do whatever it takes to keep my sanity.
You can use powershell.
From this question:
function ProcessWeb($currentWeb)
{
if([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($currentWeb))
{
$publishingWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($currentWeb)
$publishingPages = $publishingWeb.GetPublishingPages()
foreach ($publishingPage in $publishingPages)
{
if($publishingPage.ListItem.File.CheckOutStatus -eq "None")
{
UpdatePage -page $publishingPage
}
}
Write-Host -ForegroundColor red "FINISHED"
}
else
{
Write-Host -Foregroundcolor Red "^ not a publishing site"
}
}
function UpdatePage($page)
{
$page.CheckOut();
Write-Host -Foregroundcolor green $page.Url;
$NewPageContent = $page["PublishingPageContent"].Replace("/place1/place2/link","/place3/place4/link");
$page["PublishingPageContent"] = $NewPageContent
$page.ListItem.Update();
$page.CheckIn("nothing");
$page.ListItem.File.Approve("Updated PublishingPageContent to replate place1/place2 with place3/place4");
}
ProcessWeb(Get-SPWeb -identity http://myintranet.com)
Note that you will need to work out how a good replace statement will work.
Also this automates changes that could go wrong, so make sure you do it first on a dev/uat environment before backing up the content database on production and then finally giving it a go.

Resources