I am using ASPUpload to do file uploads for a web form, the current form i am working on updates a record in the database so you have the option to change the filename, i have the following check
If Upload.Form("imageFilename-bound") <> "" And Upload.Files = null Then
skipUpload = true
End If
when the page is loaded, the filename in database is made to be the value of a read-only text box imageFilename-bound while the file input field imageFilename is used to select a file. so the Psudo Code of the above is
IF [our previous image name] is not empty AND [we have not received a
file to upload] THEN {We are not uploading a file}
now since there is the option that the user doesn't want to change the file and file upload has only recently been suggested (after the form was completed) i don't want to change to much so anything to do with file uploading (including validation of size, type etc) i have put in a If skipUpload = false Then condition.
If i remove the And Upload.Files = null part i don't get any errors however when updating and i do go to change the image it doesn't do it (as imageFilename-bound is not a blank string thus the if statement is correct) however when i add the And Upload.Files = null part i get a 500 error and thus i can't actully see the problem (i am forced to test on a machine which has no error logging)
So my question is, how do i check with ASPUpload if my file input field did receive a file?
i have got the page to work with this code
skipUpload = false
If Upload.Form("imageFilename-bound") <> "" Then
skipUpload = true
For Each File in Upload.Files
skipUpload = false
Next
End If
Psudo:
IF [our previous image name] is not empty THEN
{We are not uploading a file}
FOR EACH [Submitted file]
{we actually are going to be uploading}
this does what i want but i feel this is very inelegant, having to use a Loop to check if i have submitted any file. i am still looking for a better answer
Related
I'm making a Windows vb.net form application in Visual Studio 2015, where user can either preview an image in a PictureBox by importing it from a file dialog browser, or from a web url. If the user chooses to import it from its computer using the file dialog, the preview will automatically load once it has selected the image file.
If user accidentally fills both url and file dialog, i want to clear the TextBox of the url (called url_cover), the TextBox displaying the name of file imported in file dialog (called Browse.FileName) and the PictureBox preview (called preview), and also display a MessageBox telling user to try again, using only one of the import options.
I've already tried making a basic if statement which (until there everything normal) :
If url_cover.Text <> Nothing And Browse.FileName <> Nothing Then
MsgBox("Please do not import image using both file browser and URL.", [vbOKOnly], "Warning")
url_cover.Clear() Browse.FileName = Nothing preview.Enabled = False
I was expecting all these things to happen if i filled both url and file browser, but i came out with an error telling me that an end of statement was expected after the second instruction (which is url_cover.Clear()).
I tried switching the order in which the three instructions had to be executed, but every time it was the same, after the second instruction, an end of statement was expected...
Hope my explanations have been clear, and my question is how can i execute more than 2 instructions after the condition of my If statement has been completed.
If you want more than one statement to execute if a condition is met, then you need to enclose it in a block that ends with End If.
Your code will only execute the messagebox if the conditions are satisfied and then try to execute the rest whether the condition is met or not. You're getting the End Of Statement Expected error because you're trying to put several statements on one line.
Try this ..
If url_cover.Text <> Nothing And Browse.FileName <> Nothing Then
MsgBox("Please do not import image using both file browser and URL.", [vbOKOnly], Warning")
url_cover.Clear()
Browse.FileName = Nothing
preview.Enabled = False
End If
Try this out... You can use : to separate statements if you want them on one line.
If Not String.IsNullOrEmpty(url_cover.Text) AndAlso Not String.IsNullOrEmpty(Browse.FileName) Then MsgBox("Please do not import image using both file browser and URL.", [vbOKOnly], "Warning") : url_cover.Clear() : Browse.FileName = String.Empty : preview.Enabled = False
Or block...
If url_cover.Text <> Nothing And Browse.FileName <> Nothing Then
MsgBox("Please do not import image using both file browser and URL.", [vbOKOnly], "Warning")
url_cover.Clear()
Browse.FileName = Nothing
preview.Enabled = False
End If
IMHO, look into String.IsNullOrEmpty, Multiple statements in one line and the AndAlso operator. Also try to avoid the :, if statements can become long, obscure readability etc, but nothing is wrong in using it.
Please consider adding a comment if you think this post can be improved.
I get a partial answer from one of your previous questions and answers(with an error) but not complete. The My.Computer.Network.DownloadFile(URi, destination filename, , , , , ) MSDN says that the next to last parameter is the timeout parameter, 1000 ms default, i.e., one second and then the last parameter is to indicate overwrite True or False. However there is no indication that you can use some parameter somewhere to overwrite the destination file. How can this be done?
You can also check the file existence before you execute the download.
If File.Exists("my_zip_file_location") Then
'delete the file'
File.Delete("my_zip_file_location")
'Download it again'
My.Computer.Network.DownloadFile("your_new_zip_file_location")
End If
I have a file exists under this path:
//path/folder1/folder2/datafile.gdp
It is an input to an external program being called from vba in this manner:
Sub RunProgram()
Dim wsh As Object
SetCurrentDirectory "\\path\"
ChDir "\\path\folder1\folder2\" 'Set Directory
Set wsh = VBA.CreateObject("WScript.Shell")
check = CurDir
Statusnum = wsh.Run(Command:="program.exe ""\\path\folder1\folder2\datafile.gdp""", WindowStyle:=1, waitonreturn:=True)
But on the final line, including \path\folder1\folder2\ before the input file name appears to cause the external program to want to write some files into a duplicated directory that doesn't exist, causing an error. It used to work in this format before the .exe was updated by an external company. It now wants to write some files here, all prefixed with the name of my input file:
\\path\folder1\folder2\PATH\FOLDER1\FOLDER2\
Hoping to fix this, I changed the final line of the code to this, following some comments on a previous post here on SO:
Statusnum = wsh.Run(Command:="program.exe ""datafile.gdp""", WindowStyle:=1, waitonreturn:=True)
Since the directory is set correctly prior to calling the .exe, I thought removing the path for the input file would solve the issue.
The program now launches, but doesn't appear to load the input file with it and no longer runs calculations automatically in the background as it should. Instead, it launches and the main .exe window pops up to the user as if it had just been launched for setting up a new project, calculations don't occur automatically.
To check which directory the VBA code was try to pull my datafile.gdp from, I created these loops directly before calling the .exe:
If Len(Dir("\\path\folder1\folder2\datafile.gdp")) = 0 Then
FileIsMissing1 = True 'I use Excel-VBA watches to break if true
End If
If Len(Dir("datafile.gdp")) = 0 Then
FileIsMissing2 = True
End If
Bizarrely, neither of these loops causes a break. The file only exists in
\\path\folder1\folder2\datafile.gdp
Not in the duplicated directory... so why are both of these statements satisfied? Does entering the directory make no difference even when the current directory has been set? The current directory seems to be impacting the line:
Statusnum = wsh.Run(Command:="program.exe ""\\path\folder1\folder2\datafile.gdp""", WindowStyle:=1, waitonreturn:=True)
But not these if loops, and I'm not sure why.
I'm saving a excel file one share Point into text file. after the saving, I wanna check Dir(sharePointPath).
It will always return "" unless I manually refresh the corresponding folder.
the code would be like the following:
ActiveWorkbook.SaveAs sharePointPath, xlTextWindows
ActiveWorkbook.Close
While Dir(sharePointPath) = ""
MsgBox "not exist"
Wend
The reason I wanna check Dir(sharePointPath) is that I wanna open that file later
open sharePointPath for binary access read as
which always override the text file because open can't find the file.
what should I do to fix this problem?
EDIT:
sharePointPath = {server}\rule_books\Shared Documents\Rule books\NAME - Demo and Testing Client\Text Files\test.txt before saveAS and after close.
dir(sharePointPath) = "" before and after. occasionally dir(sharePointPath) = test.txt.
but if I wait for a while after close to excute dir(sharePointPath), it will return test.txt more often. i guess vba take some time to write and show the new file.
I gave up, and create a local tmp file on user's end machine for work around
`Dim medium As String = TextBox1.Text
Dim data_xml = XElement.Load("Assets\Manager.xml")
'next quaries the xml for desired attributes
Dim query = From DataTable1 In data_xml.Descendants("DataTable1")
Where (DataTable1.Attribute("Medium").Value = medium)
Select Uname = DataTable1.Attribute("Username").Value
For Each result In query
'displays results to textbox
TextBox2.Text = result
Next
I try to use this code to read from an xml file in the assets but the file does not seem to exist
At the declaration of the xelement.load("Assets\Manager.xml") I get this error
An exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll but was not handled in user code
Additional information: Could not find file 'C:\Data\SharedData\PhoneTools\AppxLayouts\d5d3a1e7-56d7-477c-bcd2-f949f3374de1VS.Debug_AnyCPU.NAME\Assets\Manager.xml'.
If there is a handler for this exception, the program may be safely continued.
Any ideas?
Steps to make it work:
Change Manager.xml Build action to Content
Change Copy to output directory to Copy if newer
Load file using XElement.Load("Assets/Manager.xml");
Edit:
Ok, since you are not willing to share more of the code even though you ask for help, there's nothing else I can do but put up an example :)
"Software" below, implemented in Visual Basic, reads and displays XML file named Manager.xml, that is set as Content in WP8 project. Working example can be found at https://github.com/mikkoviitala/read-content-xml