Visual Basic, Search box and display results in List Box - textbox

So the problem I am trying to solve requires that if the user types in a text box their user name and press enter then the files in the directory will display in the List Box. I need it to only work on the C:\Users directory. I am new to Visual Basic but not to programming so any basic advice would be helpful.

You need to do something like this:
Dim di As New IO.DirectoryInfo("c:\")
Dim diar1 As IO.FileInfo() = di.GetFiles()
Dim dra As IO.FileInfo
'list the names of all files in the specified directory
For Each dra In diar1
ListBox1.Items.Add(dra)
Next
You can read more from this site, http://www.developerfusion.com/code/3681/list-files-in-a-directory/

Related

SaveDialog suggested filenames to match extension filter

When my program displays a SaveDialog to save a file I can use the Filter and Filter Index properties to restrict the files displayed to certain extensions. Also, when I set the DefaultExt property then, as the user types a filename, matching files in the folder are displayed as suggestions in a dropdown box and one can be selected with the mouse.
For example if the filter is set to "*.xml" then only filenames matching that extension appear in the the dialog list of files. But if the user type "Test", then you will get a dropdown list of suggestion files like:
TestA.doc
TestB.xml
Test123.pdf
TestX.xml
(if those files are present in the folder)
But I would like the suggestion list to only contain the files that match the filter, such as *.xml. Is that possible? The problem is that users can hit the wrong suggestion and save their file with the wrong extension.
TSaveDialog internally uses the IFileDialog interface of Windows. That interface doesn't offer any way in which to change how to filter files in suggestion dropdown text box of File Name field.
You can :
Implement own dialog from scratch
Use component like DexExpress which is not free
Check result of save dialog after execution of it and validate the user selection file and show proper message to user if the file is not valid

Searching RichTextBox and deleting all between

I'm having a little trouble trying to figure out how to search all the text in my RichTextBox and delete everything between the parentheses (including the parentheses). I have a lot of files with different comments wrote in the parentheses that may have different text in them.
Example : This is my text in the text box (AS YOU CAN SEE HERE). I am wanting to be able to read the entire text box (This would be another comment) and delete the out.
Result: This is my text in the text box. I am wanting to be able to read the entire text box and delete the out.
The rich text box are usually longer files than just a couple lines. Any help would be gratefully appreciated.
You can use a regular expression for this:
Regex r = new Regex("\(.+?\)");
If you are using a richtextbox or a textbox:
rtb.Text = r.Replace(rtb.Text,"");
You can do this without reading the file into the richttextbox:
string filetext = File.ReadAllText("file.txt");
filetext = r.Replace(filetext,"");
File.WriteAllText("file.txt",filetext);
Or in one line:
File.WriteAllText("file.txt",r.Replace(File.ReadAllText("file.txt"),""));
You can loop all files in a directory:
foreach(string file in Directory.GetFiles(targetDirectory)
File.WriteAllText(file,r.Replace(File.ReadAllText(file),""));

Sharepoint 2007 get link to items in a custom form

I have a SharePoint Server 2007 installation. What I needed to do is to create a simple printable page/file which is populated with data from a list. For various bugs and reasons I can't do this with a word template in a word document library and I can't use workflows.
My solution so far is very rude and simple, but it gets the jobs done:
I created a new custom form called print.aspx
I insert a Custom List Form based on the display form.
Successfully pasted the text, put the data fields and added a couple of text fields for additional data that is required in the print form but not on the list item.
This print.aspx custom form won't save anything and it is not required.
Now what I want to do is place a link in the customized DispForm.aspx that leads to the printing page so when the user enters the list item and it is approved they can click to see it. At the bottom of the DispForm.aspx there will be a simple link to print.aspx saying "To print this click here". Unfortunately I have no idea how to link to the ID of the item in print.aspx.
Example:
In InternalPortal/Lists/ImportantList/DispForm.aspx?ID=5 I want the link to point to InternalPortal/Lists/ImportantList/print.aspx?ID=5
Already tried ID={#ID} and ID=item.ID but to be honest and not sure how to use them.
Edit: In summary - the link ends in ID={#ID} but it should be in the DataFormWebPart. This will not work outside of it.

ASP MVC3 - Obtaining file path

In our ASP MVC3, we need to allow the user to navigate to a shared folder on our LAN and select the file they want associated with a particular item. We want to maintain one copy of the item, so we don't want to do any uploading/downloading, we just want to store the specified file path as a field in a SQL table. What is the best method to do this? Right now I can use this helper open a file browser window and select the file, however only the file name gets stored.
#Html.TextBoxFor(model => model.Attachments[0].Filepath, new { type = "file" })
What is the best method to do this?
You could use a normal input field, not a file field:
#Html.TextBoxFor(model => model.Attachments[0].Filepath)
Now the user can copy paste the file path in this field. That's what HTML has to offer you. If it doesn't suit your needs you always have the possibilities of using some client side scripting such as a Flash movie or Silverlight that will be installed on your clients browsers and might require elevated privileges in order to access the file system.

How to dynamically generate url for image map in Oracle ApEx?

The scenario:
I have an ApEx page which pulls a record from a table. The record contains an id, the name of the chart (actually a filename) and the code for an image map as an NVARCHAR2 column called image_map.
When I render the page I have an embedded HTML region which pulls the image in using the #WORKSPACE_IMAGES#&P19_IMAGE. substitution as the src for the image.
Each chart has hot spots (defined in the image_map html markup) which point to other charts on the same ApEx page. I need to embed the:
Application ID (like &APP_ID.)
Session (like &APP_SESSION.)
My problem:
When I try to load the &APP_ID as part of the source into the database it pre-parses it and plugs in the value for the ApEx development app (e.g. 4500) instead of the actual target application (118).
Any help would be greatly appreciated.
Not a lot of feedback - guess I'm doing something atypical?
In case someone else is trying to do this, the workaround I ended up using was to have a javascript run and replace some custom replacement flags in the urls. The script is embedded in the template of the page and assigns the APEX magic fields to local variables, e.g.:
var my_app_id = '&APP_ID';
Not pretty, but it works...
Ok - I think I've left this open long enough... In the event that anyone else is trying to (mis)use apex in a similar way, it seems like the "apex way" is to use dynamic actions (which seem stable from 4.1.x) and then you can do your dynamic replace from there rather than embedding js in the page(s) themselves.
This seems to be the most maintainable, so I'll mark this as the answer - but if someone else has a better idea, I'm open to education!
I found it difficult to set a dynamic URL on a link to another page - directly - attempting to include the full URL as an individual link target doesn't work, at least in my simplistic world, I'm not an expert (as AJ said: any wisdom appreciated).
Instead, I set individual components of the url via the link, and a 'Before Header' PL/SQL process on the targeted page to combine the elements into a full url and assign it to the full url page-item:
APEX_UTIL.set_session_state(
'PG_FULL_URL',
'http...'||
v('PG_URL_COMPONENT1')||
v('PG_URL_COMPONENT2')||
'..etc..'
);
...where PG_FULL_URL is an item of Type 'Display Image', 'Based On' 'Image URL stored in Page Item Value'.
This is Apex 5.1 btw, I don't know if some of these options are new in this release.

Resources