ASP.NET - substring and LastIndexof combination
Asked By Gul Manan
20-Jan-12 11:28 AM
Example:
Dim themes as string =Directory.getDirectories(server.mapPath("~/App_themes"))
for each theme as string in themes
dropdownlist1.Items.Add(themes.substring(theme.LastIndexOf("\"+1))
Next
dipa ahuja replied to Gul Manan
Try this simple way
void getThemes()
{
string[] themes = Directory.GetDirectories(Server.MapPath("~/App_Themes"));
foreach (string t in themes)
DropDownList1.Items.Add(Path.GetFileName(t));
}
[)ia6l0 iii replied to Gul Manan
:)
You seem to be building a dropdown and let the user change the themes dynamically on an ASP.Net page. Your code has a small bug, and I guess that is why you posted it here!
Inside your foreach loop , you should refer the "theme" variable and not "themes"
Dim themes as string =Directory.getDirectories(server.mapPath("~/App_themes"))
for each theme as string in themes
dropdownlist1.Items.Add(theme.substring(theme.LastIndexOf("\"+1))
Thank you.

Net hi friends Any one send frequently asked Important questions in C# .Net, ADO .Net, Asp .Net and Sql Server. . . . . . . . tx in Advance. . . . . . Hi, Find this. . (B)What is an IL? (B A) What is scavenging? (B) What are different types of caching using cache object of ASP.NET? (B) How can you cache different version of same page using ASP.NET cache object? (A) How will implement Page Fragment Caching? (B) Can you compare ASP.NET sessions with classic ASP? (B) Which are the various modes of storing ASP.NET session
generated code override protected void OnInit( EventArgs e) { / / / / CODEGEN: This call is required by the ASP.NET Web Form Designer. / / InitializeComponent(); base .OnInit(e); } / / / <summary> / / / Required method for Designer support - do not keep on appending an incremental numeric until it is unique string sFilename = System.IO. Path .GetFileName(myFile.FileName); int file_append = 0; while (System.IO. File .Exists(Server.MapPath(sSavePath + sFilename))) { file_append++; sFilename = System.IO. Path .GetFileNameWithoutExtension(myFile.FileName) + file_append.ToString() + ".jpg" ; } / / Save the stream to disk System.IO. FileStream newFile = new System.IO. FileStream (Server.MapPath(sSavePath + sFilename), System.IO. FileMode .Create); newFile.Write(myData, 0, myData.Length); newFile.Close(); / / Check GetThumbnailImageAbort myCallBack = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback); Bitmap myBitmap; try { myBitmap = new Bitmap(Server.MapPath(sSavePath + sFilename)); / / If jpg file is a jpeg, create a thumbnail filename that is unique sThumbFile = System.IO. Path .GetFileNameWithoutExtension(myFile.FileName) + sThumbExtension + ".jpg" ; while (System.IO. File .Exists(Server.MapPath(sSavePath + sThumbFile))) { file_append++; sThumbFile = System.IO. Path .GetFileNameWithoutExtension(myFile.FileName) + file_append.ToString() + sThumbExtension + ".jpg" ; } / / Save webpage System.Drawing.Image myThumbnail = myBitmap.GetThumbnailImage(intThumbWidth, intThumbHeight, myCallBack, IntPtr .Zero); myThumbnail.Save(Server.MapPath(sSavePath + sThumbFile)); imgPicture.ImageUrl = sSavePath + sThumbFile; / / Displaying success information lblOutput.Text = "File uploaded successfully!" ; / / Destroy
Reuploading a pdf file hello, How to reupload a file in Asp.net. My project is based on ASP.Net plus Sitefinity 3.7. The first file gets uploaded and is saved in Sitefinity's fi.Name), true); } / / copy all the sub directories using recursion foreach (DirectoryInfo diSourceDir in source.GetDirectories()) { DirectoryInfo nextTargetDir = target.CreateSubdirectory(diSourceDir.Name); CopyAll(diSourceDir, nextTargetDir); } } catch (IOException ie) { } } } } Hi, Here are you if (addTopFileUpload.HasFile && addBottomFileUpload.HasFile) { try { string filepath = "~ \ Banners \ "; string topbanner = System.IO.Path.GetFileName(addTopFileUpload.FileName); string bottombanner = System.IO.Path.GetFileName(addBottomFileUpload.FileName); string dbtopfilepath = filepath + topbanner; string dbfilebottompath = filepath + bottombanner; string fileTopPathToSave = Server.MapPath(filepath) + topbanner; string fileBottomPathToSave = Server.MapPath(filepath) + bottombanner; if ((addTopFileUpload.FileName.ToLower().EndsWith(".jpg") | | addTopFileUpload
for (int i = 0; i < pathCollection.Length; i++) { string strPath = pathCollection[i]; addZipEntry(strPath, strPath.LastIndexOf(" \ ") + 1); } } protected void addZipEntry(string strPath, int baseIndex) { DirectoryInfo di = new DirectoryInfo(strPath); foreach (DirectoryInfo item in di.GetDirectories()) { addZipEntry(item.FullName, baseIndex); } foreach (FileInfo item in di.GetFiles()) { FileStream fs = File.OpenRead(item also try this using shareZiplib: protected void Btn_Upload_Click( object sender, EventArgs e) { string folder = Server.MapPath( "~ / Files / " ); string filePath = FileUpload1.PostedFile.FileName; string fileName = System.IO. Path .GetFileName(filePath); FileUpload1.PostedFile.SaveAs(folder + fileName); / / Unzip the file UnzipFile(filePath, folder); } / / After the folder theEntry; while ((theEntry = s.GetNextEntry()) ! = null ) { string directoryName = Path .GetDirectoryName(theEntry.Name); string fileName = Path .GetFileName(theEntry.Name); string serverFolder = Server.MapPath( "~ / Files / " ); / / create directory Directory .CreateDirectory(serverFolder + directoryName); if (fileName ! = String .Empty) { FileStream streamWriter = File .Create GetDirectoryName(zipFile.getName())); FileOutputStream dest = new FileOutputStream(Path.Combine(destinationPath + " \ " + Path.GetDirectoryName(zipFile.getName()), Path.GetFileName(zipFile.getName()))); try { int len = 0; sbyte [] buffer = new sbyte [7168]; while ((len = s.read using the compression methods provided in .Net. There is the example ( File Upload & Compression in ASP.Net ), where you can find more information. If you can zip a folder using the