I am using the following method to browse for a file:
OpenFileDialog.ShowDialog()
PictureNameTextEdit.Text = OpenFileDialog.FileName
Is there a way get ONLY the file name?
The FileName method returns the entire path and file name.
i.e. I want Foo.txt instead of C:\SomeDirectory\Foo.txt
Use Path.GetFileName(fullPath) to get just the filename part, like this:
OpenFileDialog.ShowDialog()
PictureNameTextEdit.Text = System.IO.Path.GetFileName(OpenFileDialog.FileName)
OpenFileDialog.ShowDialog()
PictureNameTextEdit.Text = System.IO.Path.GetFileName(OpenFileDialog.FileName)
C++ code for obtain filename and complete path in OpenFileDialog:
textBox1->Text = OpenFileDialog1->FileName; //complete path
textBox1->Text = System::IO::Path::GetFileName(OpenFileDialog1->FileName); //filename
Suppose that I did select word2010 file named as "MyFileName.docx"
This is for ONLY the selected file extension "including the dot mark, f.e (.docx)"
MsgBox(System.IO.Path.GetExtension(Opendlg.FileName))
And this for the selected File name without extension: (MyFileName)
MsgBox(System.IO.Path.GetFileNameWithoutExtension(Opendlg.FileName))
and you can try the other options for the "PATH Class" like: GetFullPath,GetDirectoryName ...and so on.
if you want just the selected name without Extension you can try this code
Imports System.IO
PictureNameTextEdit.Text = Path.GetFileNameWithoutExtension(OpenFileDialog1.FileName)
thanx
//Following code return file name only
string[] FileFullPath;
string FileName;
objOpenFileDialog.Title = "Select Center Logo";
objOpenFileDialog.ShowDialog();
FileFullPath = objOpenFileDialog.FileNames[0].ToString().Split('\\');
FileName = FileFullPath[FileFullPath.Length - 1]; //return only File Name
//Use following code if u want save other folder ,
// following code save file to CenterLogo folder which inside bin folder//
System.IO.File.Copy(OFD.FileName, Application.StartupPath +
"/CenterLogo/" + FileName, true);
Use SafeFileName instead of FileName and it will return a name (and extension) without path.
Use this code to put the filename in PictureNameTextEdit:
OpenFileDialog.ShowDialog()
PictureNameTextEdit.Text = OpenFileDialog.SafeFileName
Related
I have a folder with my text files that can read and write and work in eclipse. But, when I export to jar, it fails because the files are not found, meaning they are not exported and I don't know how to make eclipse do that. I'm sure the solution is out there, but I don't know exactly what I'm searching for. Do I make a relative directory and how? Or another source folder? What exactly do I need to do?
This shows I have a folder called conf where my files are stored but it is not there on export.
Scanner in = new Scanner(new FileReader("conf/Admins.txt"));
FileWriter out = new FileWriter("conf/CurrentUser.txt");
int id = 0;
String name = "";
String pass = "";
boolean found = false;
while(in.hasNext()) {
id = in.nextInt();
name = in.next();
pass = in.next();
if(id == userID) {
out.write(id + " " + name + " " + pass + "\n");
found = true;
break;
}
}
All I had to do was once exported, put my conf file in the same place as the exported jar file. I don't know if, theres a better way but this is a win for me.
In a meson.build file, I have some file define by :
file = files("my_filename.ext")
To build an ID, I have try to write :
myTgt = "_other_ext" + file[0][0]
And then I have this error :
meson.build:257:4: ERROR: Invalid use of addition: must be str, not File
How can I convert the file object into a valid string ?
(I have try to add .string(), but it's not the solution)
I have found solution with format function:
fmt = "_other_ext_#0#"
myTgt = fmt.format(file[0][0])
file name: abc.aspx
my code:
string Path = #"E:\documents\Data20160129110355.xls";
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "inline; filename=Data20160129110355.xls");
HttpContext.Current.Response.TransmitFile(Path);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Close();
On click of "Open" it will open the file successfully but the header of the file are not showing "Data20160129110355.xls". It's showing abc.aspx.
How to solve this problem please reply.
Hope this will help:
Content-Disposition:What are the differences between "inline" and "attachment"?
replace 'inline' with 'attachment'.
UP: try this:
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=Data20160129110355.xls");
I want to read conf.properties file but but not by giving a hard coded path, so how can I fins it? I have use the below line but its written a null value but the path was correct.
InputStream inputStream = ReadPropertyFile.class.getResourceAsStream("configuration/conf.properties");
Assuming you have configuration folder in your project & that folder contains conf.properties
Use following in your function -
String projdir = System.getProperty("user.dir");
String propfilepath = projdir+"\\config\\"+"conf.properties";
Properties p = new Properties();
p.load(new FileInputStream(propfilepath ));
String value = p.getProperty("test");
System.out.println(value); // It is returning me a value corresponding to key "test"
I am using the following method to browse for a file:
OpenFileDialog.ShowDialog()
PictureNameTextEdit.Text = OpenFileDialog.FileName
Is there a way get ONLY the file name?
The FileName method returns the entire path and file name.
i.e. I want Foo.txt instead of C:\SomeDirectory\Foo.txt
Use Path.GetFileName(fullPath) to get just the filename part, like this:
OpenFileDialog.ShowDialog()
PictureNameTextEdit.Text = System.IO.Path.GetFileName(OpenFileDialog.FileName)
OpenFileDialog.ShowDialog()
PictureNameTextEdit.Text = System.IO.Path.GetFileName(OpenFileDialog.FileName)
C++ code for obtain filename and complete path in OpenFileDialog:
textBox1->Text = OpenFileDialog1->FileName; //complete path
textBox1->Text = System::IO::Path::GetFileName(OpenFileDialog1->FileName); //filename
Suppose that I did select word2010 file named as "MyFileName.docx"
This is for ONLY the selected file extension "including the dot mark, f.e (.docx)"
MsgBox(System.IO.Path.GetExtension(Opendlg.FileName))
And this for the selected File name without extension: (MyFileName)
MsgBox(System.IO.Path.GetFileNameWithoutExtension(Opendlg.FileName))
and you can try the other options for the "PATH Class" like: GetFullPath,GetDirectoryName ...and so on.
if you want just the selected name without Extension you can try this code
Imports System.IO
PictureNameTextEdit.Text = Path.GetFileNameWithoutExtension(OpenFileDialog1.FileName)
thanx
//Following code return file name only
string[] FileFullPath;
string FileName;
objOpenFileDialog.Title = "Select Center Logo";
objOpenFileDialog.ShowDialog();
FileFullPath = objOpenFileDialog.FileNames[0].ToString().Split('\\');
FileName = FileFullPath[FileFullPath.Length - 1]; //return only File Name
//Use following code if u want save other folder ,
// following code save file to CenterLogo folder which inside bin folder//
System.IO.File.Copy(OFD.FileName, Application.StartupPath +
"/CenterLogo/" + FileName, true);
Use SafeFileName instead of FileName and it will return a name (and extension) without path.
Use this code to put the filename in PictureNameTextEdit:
OpenFileDialog.ShowDialog()
PictureNameTextEdit.Text = OpenFileDialog.SafeFileName