How to create a folder in ASP.NET
Use System.IO namespace VB.NET Dim path As String = ” try ’ Determine whether the directory exists. If Directory.Exists(path) Then Response.Write(‘That path exists already.’) Return End If ’ Try to create the directory. Dim di As DirectoryInfo = Directory.CreateDirectory(path) Response.Write((‘Directory create successfully at ‘ + Directory.GetCreationTime(path))) catch ex as Exception Response.Write (ex.Message ) end try C# string path = @’c:\MyDir’; try { // Determine whether the directory exists. if (Directory.Exists(path)) { Response.Write (‘That path exists already.’); return; } // Try to create the directory. DirectoryInfo di = Directory.CreateDirectory(path); Response.Write(‘Directory create successfully at ‘ + Directory.GetCreationTime(path)); } catch(Exception ex) { Response.Write (ex.Message ); }
What is the best way to rename a file on the webserver in code
Use namespace System.IO VB.NET File.Move(‘C:\Dir1\SomeFile.txt’, ‘C:\Dir1\RenamedFileName.txt’) C# File.Move(@’C:\Dir1\SomeFile.txt’, @’C:\Dir1\RenamedFileName.txt’) Refer Rename Function FileInfo.MoveTo Method Note: In a Web application, the code is running in the context of the machine\ASPNET account, which has limited privileges. If the error you are getting pertains to permissions, you might need to grant to the machine\ASPNET account the rights to create and delete files in the directory where you’re working. Note that this could be a security issue.
How to extract the information between the ImageUrl of an Advertisement file
Use namespace System.Xml VB.NET Dim xmlDoc As New XmlDocument xmlDoc.Load(Server.MapPath(AdRotator1.AdvertisementFile)) Dim imgArrList As New ArrayList Dim xmlNode As XmlNode For Each xmlNode In xmlDoc.SelectNodes(‘/Advertisements/Ad/ImageUrl’) imgArrList.Add(xmlNode.InnerText) Next C# XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(Server.MapPath(AdRotator1.AdvertisementFile)); ArrayList imgArrList = new ArrayList(); foreach (XmlNode xmlNode in xmlDoc.SelectNodes(‘/Advertisements/Ad/ImageUrl’)) { imgArrList.Add(xmlNode.InnerText); }
Why do I get a blank image when I set the KeywordFilter property of the AdRotator
If the KeywordFilter property of the AdRotator control is set to a keyword that does not correspond to any element in the Advertisement file then you may get a blank image. Here is some code that should work properly. <asp:AdRotator id=’AdRotator1′ AdvertisementFile=’adrot.xml’ runat=’server’ Width=’468px’ KeywordFilter =’book’ Height=’60px’></asp:AdRotator> adrot.xml <Advertisements> <Ad> <ImageUrl>b2346.jpg</ImageUrl> <NavigateUrl>http://ww.syncfusion.com</NavigateUrl> <AlternateText> The site for ASP.Net FAQs </AlternateText> <Impressions>5</Impressions> <Keyword>book</Keyword> </Ad> </Advertisements>
How to check if nothing is selected in a CheckBoxList without using a loop to parse through all the items
You can check if CheckBoxList.SelectedIndex equals to -1 which means nothing is selected.