I am using WinSCP .NET assembly to transfer files by FTP. Couple days ago I developed new module to show pictures in PictureBox control. What I would like to achieve is to list picture's paths inside listbox or whatever else and then when click on this path to be able to open the picture in PictureBox. The point is pictures are on remote location on my FTP and I have no idea is it possible using WinSCP (FTP) to use get their path and then using the paths to show up given picture inside PictureBox. Anyone has idea is it possible or not?
You have to download the file to a local temporary file and load the file to the picture box. You cannot load the remote file directly.
' Unique temporary path
Dim tempPath As String = Path.GetTempFileName()
' Download the image
session.GetFiles(RemotePath.EscapeFileMask(remoteImagePath), tempPath).Check()
' Load tempPath to picture box
<your code here>
' Delete the temporary file
File.Delete(tempPath)
(I do not do VB.NET, so the syntax may not be 100% correct)
Related
I'm using MS Access 2003 for Special and old problems with the .mdb project
I want to embed my files like .txt or .exe or .pdf and run them at runtime or write that on disk.
What have I tried :
enter image description here
I don't know what's the code to do what I need I couldn't find my solution on internet.
Private Sub Form_Load()
'Me.OLEUnbound2.Application.Run
Dim obj As Object
Set obj = Me.OLEBound1.Object
'obj.DoVerb (acPrimaryVerb)
End Sub
Update:
I wrote a C# program called BMH.exe, which I open and run through Access, but I want this file to be in my source in any way possible so that the user does not have to place this file next to the program or somewhere It has Windows,
I also don't want to do things like downloading from the site, creating an installation file, I just want to access this program in any possible way through the embedded file itself, which is in the form of OLE Object and from the Packager Shell class. Write the object to a specific address or run it directly from Access itself
You can save the file as attachment in attachement field. If it will not accept an .exe file switch the extension and switch it back when exporting, you can do all this with code. Alternatively you can store the file as binary in an Ole field.
I'm starting to play around with FileStream to make a text document. When you do this, you have to clarify a path. Is there a way to create the text document in the folder the EXE file is in?
(I'm asking this because this program is meant to be downloaded, so I think I can't clarify a path specific to my computer)
Thank you!
You're right, you can't bake a path into your program that is specific to your computer because then it won't work on the user's computer
Jimi makes the wise point that often programs are installed to C:\Program Files or similar and it's not automatically possible to write to subfolders in there - you'll have to get into asking the user for permission (Elevation) .. headache
Better to decide what you want the path for:
If you need a temporary path to e.g. download something to then throw it away you can call Path.GetTempFilename() or Path.GetTempPath() - the former creates a 0 byte file with a random name in the user's temp folder, and returns the path. The latter gives you the path to the temp folder so you can create your own file
If the file is to have some permanence, such as the user saving his work, you should ask the user for it. SaveFileDialog and FolderBrowserDialog are two things you can drop on your windows form and then call ShowDialog() on to show the uer a UI where they pick a path. After they OK or Cancel, you check if they OK'd or Cancel and proceed using the dialog's Filename or SelectedPath respectively (if they OK'd)
When you're writing your files it's easier not to use FileStream unless you really need to seek in the file etc. Easier to just:
System.IO.File.WriteAllText(path here, contents here)
If you have to write the contents of a string variable to a file
The best way to create a text file, would be to use CreateText method. It will create a file besides the executable program file. You can go the following way.
Dim sw as StreamWriter = File.CreateText("myfile.txt")
Dim str as String = "Your text"
sw.Write(str)
sw.Flush()
sw.Close()
I have an .xlsm file with an ActiveX Microsoft Web Browser control ("Shell.Explorer.2").
I use VBA to open an image inside of it:
WebBrowser.Navigate Application.ActiveWorkbook.Path & "\image.gif"
I know that if I put an image on the worksheet it will be saved inside the .xlsm file. Such images are stored in the .xlsm (which is of ZIP structure) at \xl\media\ 'folder'.
Now I'd like to move the image from the workbook's path into the .xlsm file itself. How can I then address this image from the WebBrowser control? Should I navigate to a file inside of .xlsm as to resource or could I refer to a shape holding the image?
I know about solution based on copying (or exporting) the image from the shape and creating a dynamic HTML to include this newly copied image. I'd still like to find a way without copying/exporting it.
Thanks!
How can I create and automatically save a picture to resources.resx in vb.net?
I tried but it only saves to the resources folder. What I want is to automatically save it to the resources inside the vb. Thank you.
I don't know if this is possible, but why don't you just save it to a custom folder? Maybe even in your application folder (Debug) so that you only have to access it with it's name.
I suggest you save it in a folder that you make in your debug folder, maybe call it Images. Then just save the image to the folder and you're done. After this you will always be able to access this image with dim ImagePath as String = "Images/yourpicture.jpg"
I assume you know how to save an image?
Image.Save(ImagePath, System.Drawing.Imaging.ImageFormat.Jpeg)
i am using FileOpenDialog control to save file in C: drive,
Now i want to create New Folder and save the file in that folder with FileOpenDialog.
and also from other forms i have to store different file in that same foldr.
Please any one suggest me.
i think this link may help you
http://social.msdn.microsoft.com/Forums/vstudio/en-US/9bc2c92a-b22f-484c-9a15-0aebf639422d/folder-browser-dialog-in-vbnet-2010
by the way you should use SavefFileDialog or FolderBrowserDialog
First of all, you should use the SaveFileDialog to save the file. Not the file open dialog. The SaveFileDialog control will automatically let the user also create a folder -- just open the dialog in run-time mode and right click inside and see.. New > New Folder. Once the user navigates into this newly created folder and specifies the file name, all you need to do is to save the file.
Alternately, if you want to use a fixed subfolder, don't prompt the user to create the folder for you. Instead after the dialog is dismissed, do this --
string savePath = saveFileDialog1.FileName;
string directory = System.IO.Path.GetDirectoryName(savePath);
savePath = string.Format(
"{0}\\MySubFolder\\{1}",
directory,
System.IO.Path.GetFileName(savePath)
);
Save the file to the path in "savePath".
(PS: Sorry my above snippet is in C#, but you should be able to easily convert it to VB.NET).