Using MakePath

Using MakePath

MakePath Method

  • Used to combine two strings into a path – replace folderpath with the folder location, such as “c:\inetpub\wwwroot\sitecore1\Website\layouts\Project1”, and replace filename with the name of the file
  • Add the separator character using single quotes     - string path = Sitecore.IO.FileUtil.MakePath(@"folderpath", "filename", '\\');

MakePath C# Web Control Code

Sitecore.Data.Items.Item item = this.GetItem();
if (item == null) return;

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.Write("C# Web Control Real-time Output");
output.RenderEndTag();

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-size:x-small; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
string displayName = Sitecore.StringUtil.GetString(item.DisplayName, item.Name);
//using : for colon and ? for question mark and   for space
output.Write("{0}: {1}", "Item", displayName);
output.RenderEndTag(); //P

string folderPath = "C:\\inetpub\\wwwroot\\TIC2\\Website\\images\\TIC\\buttons";
string fileName1 = "search.gif";
string fileName2 = "searchicon.gif";
char separator = '\\';
string file1FullPath = Sitecore.IO.FileUtil.MakePath(folderPath, fileName1, separator);
string file1Exists = Sitecore.IO.FileUtil.Exists(file1FullPath).ToString();
string file2FullPath = Sitecore.IO.FileUtil.MakePath(folderPath, fileName2, separator);
string file2Exists = Sitecore.IO.FileUtil.Exists(file2FullPath).ToString();

if (!string.IsNullOrEmpty(file1FullPath) && !string.IsNullOrEmpty(file2FullPath))
{
    output.Write("{0}&#58;&#160;{1}", "Folder Path", "<b>" + folderPath + "</b><br/><br/>");
    output.Write("{0}&#58;&#160;{1}", "File1 Name", "<b>" + fileName1 + "</b><br/>");
    output.Write("{0}&#58;&#160;{1}", "File1 Path", "<b>" + file1FullPath + "</b><br/>");
    output.Write("{0}&#63;&#160;{1}", "File1 Exists", "<b>" + file1Exists + "</b><br/><br/>");
    output.Write("{0}&#58;&#160;{1}", "File2 Name", "<b>" + fileName2 + "</b><br/>");
    output.Write("{0}&#58;&#160;{1}", "File2 Path", "<b>" + file2FullPath + "</b><br/>");
    output.Write("{0}&#63;&#160;{1}", "File2 Exists", "<b>" + file2Exists + "</b>");
}

output.RenderEndTag(); //Div


MakePath C# Web Control Output

Folder Path: C:\inetpub\wwwroot\TIC66Live\Website\images\TIC\buttons

File1 Name: search.gif
File1 Path: C:\inetpub\wwwroot\TIC66Live\Website\images\TIC\buttons\search.gif
File1 Exists? True

File2 Name: searchicon.gif
File2 Path: C:\inetpub\wwwroot\TIC66Live\Website\images\TIC\buttons\searchicon.gif
File2 Exists? False