Search Results

Search found 386 results on 16 pages for 'fileupload'.

Page 16/16 | < Previous Page | 12 13 14 15 16 

  • Does writing data to server using Java URL class require response from server?

    - by gigadot
    I am trying to upload files using Java URL class and I have found a previous question on stack-overflow which explains very well about the details, so I try to follow it. And below is my code adopted from the sniplet given in the answer. My problem is that if I don't make a call to one of connection.getResponseCode() or connection.getInputStream() or connection.getResponseMessage() or anything which is related to reponse from the server, the request will never be sent to server. Why do I need to do this? Or is there any way to write the data without getting the response? P.S. I have developed a server-side uploading servlet which accepts multipart/form-data and save it to files using FileUpload. It is stable and definitely working without any problem so this is not where my problem is generated. import java.io.Closeable; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; import java.io.PrintWriter; import java.net.HttpURLConnection; import java.net.URL; import org.apache.commons.io.IOUtils; public class URLUploader { public static void closeQuietly(Closeable... objs) { for (Closeable closeable : objs) { IOUtils.closeQuietly(closeable); } } public static void main(String[] args) throws IOException { File textFile = new File("D:\\file.zip"); String boundary = Long.toHexString(System.currentTimeMillis()); // Just generate some unique random value. HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:8080/upslet/upload").openConnection(); connection.setDoOutput(true); connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); OutputStream output = output = connection.getOutputStream(); PrintWriter writer = writer = new PrintWriter(output, true); // Send text file. writer.println("--" + boundary); writer.println("Content-Disposition: form-data; name=\"file1\"; filename=\"" + textFile.getName() + "\""); writer.println("Content-Type: application/octet-stream"); FileInputStream fin = new FileInputStream(textFile); writer.println(); IOUtils.copy(fin, output); writer.println(); // End of multipart/form-data. writer.println("--" + boundary + "--"); output.flush(); closeQuietly(fin, writer, output); // Above request will never be sent if .getInputStream() or .getResponseCode() or .getResponseMessage() does not get called. connection.getResponseCode(); } }

    Read the article

  • Sening a file from memory (rather than disk) over HTTP using libcurl

    - by cinek1lol
    Hi! I would like to send pictures via a program written in C + +. - OK WinExec("C:\\curl\\curl.exe -H Expect: -F \"fileupload=@C:\\curl\\ok.jpg\" -F \"xml=yes\" -# \"http://www.imageshack.us/index.php\" -o data.txt -A \"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1\" -e \"http://www.imageshack.us\"", NULL); It works, but I would like to send the pictures from pre-loaded carrier to a variable char (you know what I mean? First off, I load the pictures into a variable and then send the variable), cause now I have to specify the path of the picture on a disk. I wanted to write this program in c++ by using the curl library, not through exe. extension. I have also found such a program (which has been modified by me a bit) #include <stdio.h> #include <string.h> #include <iostream> #include <curl/curl.h> #include <curl/types.h> #include <curl/easy.h> int main(int argc, char *argv[]) { CURL *curl; CURLcode res; struct curl_httppost *formpost=NULL; struct curl_httppost *lastptr=NULL; struct curl_slist *headerlist=NULL; static const char buf[] = "Expect:"; curl_global_init(CURL_GLOBAL_ALL); /* Fill in the file upload field */ curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "send", CURLFORM_FILE, "nowy.jpg", CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "nowy.jpg", CURLFORM_COPYCONTENTS, "nowy.jpg", CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "submit", CURLFORM_COPYCONTENTS, "send", CURLFORM_END); curl = curl_easy_init(); headerlist = curl_slist_append(headerlist, buf); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "http://www.imageshack.us/index.php"); if ( (argc == 2) && (!strcmp(argv[1], "xml=yes")) ) curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); res = curl_easy_perform(curl); curl_easy_cleanup(curl); curl_formfree(formpost); curl_slist_free_all (headerlist); } system("pause"); return 0; }

    Read the article

  • [c++] upload image to imageshack

    - by cinek1lol
    Hi! I would like to send pictures via a program written in C + +. - OK WinExec("C:\\curl\\curl.exe -H Expect: -F \"fileupload=@C:\\curl\\ok.jpg\" -F \"xml=yes\" -# \"http://www.imageshack.us/index.php\" -o data.txt -A \"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1\" -e \"http://www.imageshack.us\"", NULL); It works, but I would like to send the pictures from pre-loaded carrier to a variable char (you know what I mean? First off, I load the pictures into a variable and then send the variable), cause now I have to specify the path of the picture on a disk. I wanted to write this program in c++ by using the curl library, not through exe. extension. I have also found such a program (which has been modified by me a bit) #include <stdio.h> #include <string.h> #include <iostream> #include <curl/curl.h> #include <curl/types.h> #include <curl/easy.h> int main(int argc, char *argv[]) { CURL *curl; CURLcode res; struct curl_httppost *formpost=NULL; struct curl_httppost *lastptr=NULL; struct curl_slist *headerlist=NULL; static const char buf[] = "Expect:"; curl_global_init(CURL_GLOBAL_ALL); /* Fill in the file upload field */ curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "send", CURLFORM_FILE, "nowy.jpg", CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "nowy.jpg", CURLFORM_COPYCONTENTS, "nowy.jpg", CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "submit", CURLFORM_COPYCONTENTS, "send", CURLFORM_END); curl = curl_easy_init(); headerlist = curl_slist_append(headerlist, buf); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "http://www.imageshack.us/index.php"); if ( (argc == 2) && (!strcmp(argv[1], "xml=yes")) ) curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); res = curl_easy_perform(curl); curl_easy_cleanup(curl); curl_formfree(formpost); curl_slist_free_all (headerlist); } system("pause"); return 0; }

    Read the article

  • [c++] upload image to imageshack

    - by cinek1lol
    Hi. I would like to send pictures via a program written in C + + I wrote such a thing using curl.exe WinExec("C:\\curl\\curl.exe -H Expect: -F \"fileupload=@C:\\curl\\ok.jpg\" -F \"xml=yes\" -# \"http://www.imageshack.us/index.php\" -o data.txt -A \"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1\" -e \"http://www.imageshack.us\"", NULL); This only works that I would like to send pictures to a variable pre-loaded char (you know what I mean? first reads the pictures into a variable and then send that variable), because now I have to specify the path to the images on disk I wanted to make this program was written in C + + using the curl library, and not the exe. I found it such a program (which some have modified) #include <stdio.h> #include <string.h> #include <iostream> #include <curl/curl.h> #include <curl/types.h> #include <curl/easy.h> int main(int argc, char *argv[]) { CURL *curl; CURLcode res; struct curl_httppost *formpost=NULL; struct curl_httppost *lastptr=NULL; struct curl_slist *headerlist=NULL; static const char buf[] = "Expect:"; curl_global_init(CURL_GLOBAL_ALL); /* Fill in the file upload field */ curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "send", CURLFORM_FILE, "nowy.jpg", CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "nowy.jpg", CURLFORM_COPYCONTENTS, "nowy.jpg", CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "submit", CURLFORM_COPYCONTENTS, "send", CURLFORM_END); curl = curl_easy_init(); headerlist = curl_slist_append(headerlist, buf); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "http://www.imageshack.us/index.php"); if ( (argc == 2) && (!strcmp(argv[1], "xml=yes")) ) curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); res = curl_easy_perform(curl); curl_easy_cleanup(curl); curl_formfree(formpost); curl_slist_free_all (headerlist); } system("pause"); return 0; } I will be grateful for any help

    Read the article

  • Sending a file from memory (rather than disk) over HTTP using libcurl

    - by cinek1lol
    Hi! I would like to send pictures via a program written in C + +. - OK WinExec("C:\\curl\\curl.exe -H Expect: -F \"fileupload=@C:\\curl\\ok.jpg\" -F \"xml=yes\" -# \"http://www.imageshack.us/index.php\" -o data.txt -A \"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1\" -e \"http://www.imageshack.us\"", NULL); It works, but I would like to send the pictures from pre-loaded carrier to a variable char (you know what I mean? First off, I load the pictures into a variable and then send the variable), cause now I have to specify the path of the picture on a disk. I wanted to write this program in c++ by using the curl library, not through exe. extension. I have also found such a program (which has been modified by me a bit) #include <stdio.h> #include <string.h> #include <iostream> #include <curl/curl.h> #include <curl/types.h> #include <curl/easy.h> int main(int argc, char *argv[]) { CURL *curl; CURLcode res; struct curl_httppost *formpost=NULL; struct curl_httppost *lastptr=NULL; struct curl_slist *headerlist=NULL; static const char buf[] = "Expect:"; curl_global_init(CURL_GLOBAL_ALL); /* Fill in the file upload field */ curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "send", CURLFORM_FILE, "nowy.jpg", CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "nowy.jpg", CURLFORM_COPYCONTENTS, "nowy.jpg", CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "submit", CURLFORM_COPYCONTENTS, "send", CURLFORM_END); curl = curl_easy_init(); headerlist = curl_slist_append(headerlist, buf); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "http://www.imageshack.us/index.php"); if ( (argc == 2) && (!strcmp(argv[1], "xml=yes")) ) curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); res = curl_easy_perform(curl); curl_easy_cleanup(curl); curl_formfree(formpost); curl_slist_free_all (headerlist); } system("pause"); return 0; }

    Read the article

  • Uploading and Importing CSV file to SQL Server in ASP.NET WebForms

    - by Vincent Maverick Durano
    Few weeks ago I was working with a small internal project  that involves importing CSV file to Sql Server database and thought I'd share the simple implementation that I did on the project. In this post I will demonstrate how to upload and import CSV file to SQL Server database. As some may have already know, importing CSV file to SQL Server is easy and simple but difficulties arise when the CSV file contains, many columns with different data types. Basically, the provider cannot differentiate data types between the columns or the rows, blindly it will consider them as a data type based on first few rows and leave all the data which does not match the data type. To overcome this problem, I used schema.ini file to define the data type of the CSV file and allow the provider to read that and recognize the exact data types of each column. Now what is schema.ini? Taken from the documentation: The Schema.ini is a information file, used to define the data structure and format of each column that contains data in the CSV file. If schema.ini file exists in the directory, Microsoft.Jet.OLEDB provider automatically reads it and recognizes the data type information of each column in the CSV file. Thus, the provider intelligently avoids the misinterpretation of data types before inserting the data into the database. For more information see: http://msdn.microsoft.com/en-us/library/ms709353%28VS.85%29.aspx Points to remember before creating schema.ini:   1. The schema information file, must always named as 'schema.ini'.   2. The schema.ini file must be kept in the same directory where the CSV file exists.   3. The schema.ini file must be created before reading the CSV file.   4. The first line of the schema.ini, must the name of the CSV file, followed by the properties of the CSV file, and then the properties of the each column in the CSV file. Here's an example of how the schema looked like: [Employee.csv] ColNameHeader=False Format=CSVDelimited DateTimeFormat=dd-MMM-yyyy Col1=EmployeeID Long Col2=EmployeeFirstName Text Width 100 Col3=EmployeeLastName Text Width 50 Col4=EmployeeEmailAddress Text Width 50 To get started lets's go a head and create a simple blank database. Just for the purpose of this demo I created a database called TestDB. After creating the database then lets go a head and fire up Visual Studio and then create a new WebApplication project. Under the root application create a folder called UploadedCSVFiles and then place the schema.ini on that folder. The uploaded CSV files will be stored in this folder after the user imports the file. Now add a WebForm in the project and set up the HTML mark up and add one (1) FileUpload control one(1)Button and three (3) Label controls. After that we can now proceed with the codes for uploading and importing the CSV file to SQL Server database. Here are the full code blocks below: 1: using System; 2: using System.Data; 3: using System.Data.SqlClient; 4: using System.Data.OleDb; 5: using System.IO; 6: using System.Text; 7:   8: namespace WebApplication1 9: { 10: public partial class CSVToSQLImporting : System.Web.UI.Page 11: { 12: private string GetConnectionString() 13: { 14: return System.Configuration.ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString; 15: } 16: private void CreateDatabaseTable(DataTable dt, string tableName) 17: { 18:   19: string sqlQuery = string.Empty; 20: string sqlDBType = string.Empty; 21: string dataType = string.Empty; 22: int maxLength = 0; 23: StringBuilder sb = new StringBuilder(); 24:   25: sb.AppendFormat(string.Format("CREATE TABLE {0} (", tableName)); 26:   27: for (int i = 0; i < dt.Columns.Count; i++) 28: { 29: dataType = dt.Columns[i].DataType.ToString(); 30: if (dataType == "System.Int32") 31: { 32: sqlDBType = "INT"; 33: } 34: else if (dataType == "System.String") 35: { 36: sqlDBType = "NVARCHAR"; 37: maxLength = dt.Columns[i].MaxLength; 38: } 39:   40: if (maxLength > 0) 41: { 42: sb.AppendFormat(string.Format(" {0} {1} ({2}), ", dt.Columns[i].ColumnName, sqlDBType, maxLength)); 43: } 44: else 45: { 46: sb.AppendFormat(string.Format(" {0} {1}, ", dt.Columns[i].ColumnName, sqlDBType)); 47: } 48: } 49:   50: sqlQuery = sb.ToString(); 51: sqlQuery = sqlQuery.Trim().TrimEnd(','); 52: sqlQuery = sqlQuery + " )"; 53:   54: using (SqlConnection sqlConn = new SqlConnection(GetConnectionString())) 55: { 56: sqlConn.Open(); 57: SqlCommand sqlCmd = new SqlCommand(sqlQuery, sqlConn); 58: sqlCmd.ExecuteNonQuery(); 59: sqlConn.Close(); 60: } 61:   62: } 63: private void LoadDataToDatabase(string tableName, string fileFullPath, string delimeter) 64: { 65: string sqlQuery = string.Empty; 66: StringBuilder sb = new StringBuilder(); 67:   68: sb.AppendFormat(string.Format("BULK INSERT {0} ", tableName)); 69: sb.AppendFormat(string.Format(" FROM '{0}'", fileFullPath)); 70: sb.AppendFormat(string.Format(" WITH ( FIELDTERMINATOR = '{0}' , ROWTERMINATOR = '\n' )", delimeter)); 71:   72: sqlQuery = sb.ToString(); 73:   74: using (SqlConnection sqlConn = new SqlConnection(GetConnectionString())) 75: { 76: sqlConn.Open(); 77: SqlCommand sqlCmd = new SqlCommand(sqlQuery, sqlConn); 78: sqlCmd.ExecuteNonQuery(); 79: sqlConn.Close(); 80: } 81: } 82: protected void Page_Load(object sender, EventArgs e) 83: { 84:   85: } 86: protected void BTNImport_Click(object sender, EventArgs e) 87: { 88: if (FileUpload1.HasFile) 89: { 90: FileInfo fileInfo = new FileInfo(FileUpload1.PostedFile.FileName); 91: if (fileInfo.Name.Contains(".csv")) 92: { 93:   94: string fileName = fileInfo.Name.Replace(".csv", "").ToString(); 95: string csvFilePath = Server.MapPath("UploadedCSVFiles") + "\\" + fileInfo.Name; 96:   97: //Save the CSV file in the Server inside 'MyCSVFolder' 98: FileUpload1.SaveAs(csvFilePath); 99:   100: //Fetch the location of CSV file 101: string filePath = Server.MapPath("UploadedCSVFiles") + "\\"; 102: string strSql = "SELECT * FROM [" + fileInfo.Name + "]"; 103: string strCSVConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";" + "Extended Properties='text;HDR=YES;'"; 104:   105: // load the data from CSV to DataTable 106:   107: OleDbDataAdapter adapter = new OleDbDataAdapter(strSql, strCSVConnString); 108: DataTable dtCSV = new DataTable(); 109: DataTable dtSchema = new DataTable(); 110:   111: adapter.FillSchema(dtCSV, SchemaType.Mapped); 112: adapter.Fill(dtCSV); 113:   114: if (dtCSV.Rows.Count > 0) 115: { 116: CreateDatabaseTable(dtCSV, fileName); 117: Label2.Text = string.Format("The table ({0}) has been successfully created to the database.", fileName); 118:   119: string fileFullPath = filePath + fileInfo.Name; 120: LoadDataToDatabase(fileName, fileFullPath, ","); 121:   122: Label1.Text = string.Format("({0}) records has been loaded to the table {1}.", dtCSV.Rows.Count, fileName); 123: } 124: else 125: { 126: LBLError.Text = "File is empty."; 127: } 128: } 129: else 130: { 131: LBLError.Text = "Unable to recognize file."; 132: } 133:   134: } 135: } 136: } 137: } The code above consists of three (3) private methods which are the GetConnectionString(), CreateDatabaseTable() and LoadDataToDatabase(). The GetConnectionString() is a method that returns a string. This method basically gets the connection string that is configured in the web.config file. The CreateDatabaseTable() is method that accepts two (2) parameters which are the DataTable and the filename. As the method name already suggested, this method automatically create a Table to the database based on the source DataTable and the filename of the CSV file. The LoadDataToDatabase() is a method that accepts three (3) parameters which are the tableName, fileFullPath and delimeter value. This method is where the actual saving or importing of data from CSV to SQL server happend. The codes at BTNImport_Click event handles the uploading of CSV file to the specified location and at the same time this is where the CreateDatabaseTable() and LoadDataToDatabase() are being called. If you notice I also added some basic trappings and validations within that event. Now to test the importing utility then let's create a simple data in a CSV format. Just for the simplicity of this demo let's create a CSV file and name it as "Employee" and add some data on it. Here's an example below: 1,VMS,Durano,[email protected] 2,Jennifer,Cortes,[email protected] 3,Xhaiden,Durano,[email protected] 4,Angel,Santos,[email protected] 5,Kier,Binks,[email protected] 6,Erika,Bird,[email protected] 7,Vianne,Durano,[email protected] 8,Lilibeth,Tree,[email protected] 9,Bon,Bolger,[email protected] 10,Brian,Jones,[email protected] Now save the newly created CSV file in some location in your hard drive. Okay let's run the application and browse the CSV file that we have just created. Take a look at the sample screen shots below: After browsing the CSV file. After clicking the Import Button Now if we look at the database that we have created earlier you'll notice that the Employee table is created with the imported data on it. See below screen shot.   That's it! I hope someone find this post useful! Technorati Tags: ASP.NET,CSV,SQL,C#,ADO.NET

    Read the article

  • Navigation to call action for bean class

    - by Muthu
    I am using JSF 2.0 and PrimeFaces 3.0. I have uploaded the images and have to crop the image. The images are uploaded and successfully displayed in the upload pages. When I select the images and click the crop button the corresponding crop bean is not called. If I don't select the image and click the crop button the corresponding crop bean class is called but a NullPointerException occurred. What is the problem? The Facelet view is: <h:form> <p:panel header="FILE UPLOAD WITH CROPPER" style="width:900px; margin: 0 auto; margin-top:0px"> <p:fileUpload fileUploadListener="#{photoUploadAction.handleImageUpload}" mode="advanced" update="getImageId,messages" auto="false" allowTypes="/(\.|\/)(gif|jpe?g|png)$/"/> <p:growl id="messages" showDetail="true"/> <p:growl id="uploadMessages" showSummary="true" showDetail="true"/> <h:panelGrid columns="2" > <p:imageCropper value="#{photoUploadAction.croppedImage}" id="getImageId" image="images/#{photoUploadVO.imageName}"/> </h:panelGrid> <p:commandButton value="Crop" update="getImageId" action="#{imageCropperBean.crop}" /> </p:panel> </h:form> BACKING BEAN for ImageCropper: @ManagedBean(name="imageCrop") @RequestScoped public class ImageCropperBean { private CroppedImage croppedImage; private String newFileName; private String imageName; public String getImageName() { return imageName; } public void setImageName(String imageName) { System.out.println("TEH IMAGE NAME ===="+imageName); this.imageName = imageName; } public String getNewFileName() { return newFileName; } public void setNewFileName(String newFileName) { System.out.println("AAAAAAAAAAAAAA"+this.newFileName); this.newFileName = newFileName; } public CroppedImage getCroppedImage() { return croppedImage; } public void setCroppedImage(CroppedImage croppedImage) { System.out.println("cRRRRRRRRRRRRR"+croppedImage); this.croppedImage = croppedImage; } public ImageCropperBean(){ } public String crop() { System.out.println("WELCOMEMMMMMMMMMMMMMM"); FacesContext context = FacesContext.getCurrentInstance(); ImageCropperBean imageCropperBean = (ImageCropperBean) context.getApplication().evaluateExpressionGet(context, "#{imageCropperBean}", ImageCropperBean.class); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(); newFileName = servletContext.getRealPath("") + File.separator + "cropImage" + File.separator+ "croppedImage.jpg"; System.out.println("FILE NAME NAME NAME NAME "+newFileName); String file = new File(newFileName).getName(); System.out.println("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"+file); imageCropperBean.setImageName(file); File fileFolder = new File("e:/Mecherie_project/image_web/WebContent/cropImages",file); System.out.println("FILE ANE"+file); // String target=null; FileImageOutputStream imageOutput; try { imageOutput = new FileImageOutputStream(fileFolder); System.out.println("HHHHHHHHHH=="+imageOutput); imageOutput.write(croppedImage.getBytes(), 0, croppedImage.getBytes().length); imageOutput.close(); FacesMessage msg = new FacesMessage("Succesful", file + " is cropped."); FacesContext.getCurrentInstance().addMessage(null, msg); } catch (FileNotFoundException e) { FacesMessage error = new FacesMessage(FacesMessage.SEVERITY_ERROR, "The files were not Cropped!", ""); FacesContext.getCurrentInstance().addMessage(null, error); e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); FacesMessage error = new FacesMessage(FacesMessage.SEVERITY_ERROR, "The files were not Cropped!", ""); FacesContext.getCurrentInstance().addMessage(null, error); } // System.out.println("ghfhgfghgh"+target); return "success"; } }

    Read the article

  • ASP.NET Web Page Not Available

    - by hahuang65
    It's pretty difficult to show code for ASP.NET here, so I will try my best to describe my problem. I have a FileUploadControl and a Button that calls a function when it's clicked. It seems that the Button function works when there is nothing chosen for my FileUploadControl. However, when there is something chosen in the FileUploadControl (I have selected a file to upload), there is a problem when I click the button. It completely does not matter what the function does (it could just be writing to a label, even when it has nothing to do with the FileUploadControl). The error I get is: This webpage is not available. The webpage at http://localhost:2134/UploadMedia/Default.aspx might be temporarily down or it may have moved permanently to a new web address. I have searched on Google, and people seem to have had problems with this, but different causes from me. They have said that their ASP.NET Development Server port is actually different from their port in the address bar. This is not the case for me. Also, another problem people have had is with Use Dynamic Ports. I have tried both true and false. I have also tried different ports, and I have always gotten the same error. This is really driving me crazy because it doesn't matter what the code in the buttonFunction is, it doesn't work as long as there is something in the FileUploadControl. If there is nothing, it seems to work fine. Here is the code for the ASP.NET Controls: <asp:FileUpload id="FileUploadControl" runat="server" /> <asp:Button runat="server" id="UploadButton" text="Upload" OnClick="uploadClicked" /> <br /><br /> <asp:Label runat="server" id="StatusLabel" text="Upload status: " /> And this is the code for the button function: protected void uploadClicked(object sender, EventArgs e) { if (FileUploadControl.HasFile) { string filename = Path.GetFileName(FileUploadControl.FileName); //Check if the entered username already exists in the database. String sqlDupStmt = "Select songPath from Songs where songPath ='" + Server.MapPath("~/Uploads/") + filename + "'"; SqlConnection sqlDupConn = new SqlConnection(@"Data Source = .\SQLEXPRESS; AttachDbFilename = |DataDirectory|\Database.mdf; Integrated Security = True; User Instance = True;"); SqlCommand sqlDupCmd = new SqlCommand(sqlDupStmt, sqlDupConn); sqlDupCmd.Connection.Open(); SqlDataReader sqlDupReader = sqlDupCmd.ExecuteReader(CommandBehavior.CloseConnection); if (sqlDupReader.Read()) { StatusLabel.Text = "Upload status: The file already exists."; sqlDupReader.Close(); } else { sqlDupReader.Close(); //See "How To Use DPAPI (Machine Store) from ASP.NET" for information about securely storing connection strings. String sqlStmt = "Insert into Songs values (@songpath);"; SqlConnection sqlConn = new SqlConnection(@"Data Source = .\SQLEXPRESS; AttachDbFilename = |DataDirectory|\Database.mdf; Integrated Security = True; User Instance = True; uid=sa; pwd=password;"); SqlCommand cmd = new SqlCommand(sqlStmt, sqlConn); SqlParameter sqlParam = null; //Usage of Sql parameters also helps avoid SQL Injection attacks. sqlParam = cmd.Parameters.Add("@userName", SqlDbType.VarChar, 150); sqlParam.Value = Server.MapPath("~/Uploads/") + filename; //Attempt to add the song to the database. try { sqlConn.Open(); cmd.ExecuteNonQuery(); FileUploadControl.SaveAs(Server.MapPath("~/Uploads/") + filename); songList.Items.Add(filename); StatusLabel.Text = "Upload status: File uploaded!"; } catch (Exception ex) { StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message; } finally { sqlConn.Close(); } } } } But this buttonfunction provides the same results: protected void uploadClicked(object sender, EventArgs e) { StatusLabel.Text = "FooBar"; } Has anyone had this problem before, or might know what the cause is? Thanks!

    Read the article

  • jQuery .closest returns undefined

    - by Andy Holmes
    I've got the code below which works fine, however the jquery to add the items doesnt find the data-parent-room value and just returns undefined. This is the only thing not working :( HTML: <div id="inventoryRooms"> <!--BOX SHART--> <div class="widget box formHolder" data-parent-room="1"> <!--ROOM NAME--> <form class="widget-header rooms"> <input type="text" placeholder="Type Room name" name="roomName[]" class="form-input add-room-input input-width-xxlarge"> <input type="hidden" class="roomId" name="roomId[]"> <input type="hidden" class="inventoryId" name="inventoryId[]" value="<?=$_GET['inventory_id']?>"> <div class="toolbar no-padding"> <div class="btn-group"> <span class="btn saveRoom"><i class="icon-ok"></i> Save Room</span> </div> </div> </form> <!--/END--> <!--GENERIC ROW TITLES--> <div class="widget-header header-margin hide"> <div class="row row-title"> <div class="col-md-3"><h5>ITEM</h5></div> <div class="col-md-3"><h5>DESCRIPTION</h5></div> <div class="col-md-3"><h5>CONDITION</h5></div> <div class="col-md-2"><h5>PHOTOGRAPH</h5></div> <div class="col-md-1 align-center"><h5><i class="icon-cog"> </i></h5></div> </div> </div> <!--/END--> <!--ADD ITEM--> <div class="items"> </div> <!--/END--> <div class="toolbar-small"> <div class="btn-group"> <span class="btn addItem"><i class="icon-plus"></i> Add Item</span> <span data-toggle="dropdown" class="btn dropdown-toggle"><i class="icon-gear"></i> Options<span class="button-space"></span><i class="icon-angle-down"></i></span> <ul class="dropdown-menu pull-right"> <li><a href="#"><i class="icon-trash"></i> Delete Room</a></li> </ul> </div> </div> </div> </div> jQuery: $(document).on('click','.addItem', function(){ $('<!--ROW START-->\ <form class="widget-content item">\ <div class="row">\ <div class="col-md-3"><input type="text" class="form-control" name="itemName[]"></div>\ <div class="col-md-3"><textarea class="auto form-control" name="itemDescription[]" cols="20" rows="1" style="word-wrap: break-word; resize: vertical;"></textarea></div>\ <div class="col-md-3"><textarea class="auto form-control" name="itemCondition[]" cols="20" rows="1" style="word-wrap: break-word; resize: vertical;"></textarea></div>\ <input type="hidden" class="itemId" name="itemId[]" value="">\ <input type="hidden" name="itemInventoryId[]" value="<?=$_GET["inventory_id"]?>">\ <input type="hidden" name="itemParent[]" value="'+$(this).closest().attr('data-parent-room')+'">\ <div class="col-md-2">\ <div class="fileinput-holder input-group">\ <input id="fileupload" type="file" name="files[]" data-url="uploads/">\ </div>\ </div>\ <div class="col-md-1 align-center"><i class="save icon-ok large"> </i>&nbsp;&nbsp;&nbsp;<i class="delete icon-trash large"> </i></div>\ </div>\ </form>\ <!--/ROW END-->').fadeIn(500).appendTo($(this).parents().siblings('.items')); $(this).parent().parent().siblings('.widget-header, .header-margin, .hide').removeClass('hide').fadeIn(); }); Like i say, it all works fine apart from that damn data-parent-room value. Any help is appreciated! using jQuery 1.10.1

    Read the article

  • asp.net mvc xval validation

    - by mctayl
    Hi there I am using xval for the first time, it seems to work fine for required fields, However I am having some issues first of all it does not seem to validate booleans and also client validation is not working for me, this is not a major issue for me, the one that I really need to work is the stringlength property. It seems to do something because the form is not posted when the string length is exceeded, however no error message is displayed to the user which is obviously not what I want, has anyone been able to do this successfully? My model goes like this using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.ComponentModel.DataAnnotations; namespace PitchPortal.Core { public class DocumentMetadata { //[Required] // public bool visibility { get; set; } [Required,StringLength(10, ErrorMessage = "title is too long")] public string title { get; set; } [Required, StringLength(10, ErrorMessage = "description is too long")] public string description { get; set; } [Required, StringLength(10, ErrorMessage = "summary is too long")] public string summary { get; set; } } } the html goes like this <div id="results" title="Upload results"/> <form id="myForm" action="<%=Url.Action("New") %>" method="post" enctype="multipart/form-data"> <% Html.EnableClientValidation(); %> <%= Html.ValidationSummary() %> <table> <tr> <td> <%=Html.Label("File")%></td> <td> <input type="file" id="file1" name="fileUpload" /> <br /> <%=Html.SubmitButton<DocumentController>(x => x.Upload(), "GetImage", "")%> </td> <td> <%=Html.ValidationMessage("file1")%> </td> </tr> <tr> <td> <%=Html.Label("Visible")%></td> <td> <%= Html.RadioButton( "visibility",true,true) %>true <%= Html.RadioButton("visibility", false)%>false </td> <td> <%= Html.ValidationMessage("visibility")%> </td> </tr> <tr> <td> <%=Html.Label("Title")%></td> <td> <%=Html.TextBox("doc.title")%></td> <td> <%= Html.ValidationMessage("doc.title")%></td> </tr> <tr> <td> <%=Html.Label("Description")%></td> <td><%= Html.TextArea("doc.description")%></td> <td><%= Html.ValidationMessage("doc.description")%></td> </tr> <tr> <td> <%=Html.Label("Summary")%></td> <td> <%= Html.TextArea("doc.summary")%></td> <td> <%= Html.ValidationMessage("doc.summary")%></td> </tr> <tr> <td> <%=Html.Label("Filetype")%></td> <td> <%= Html.DropDownList("Filetype_id", (IEnumerable<SelectListItem>)ViewData.Model.AllFiletypesList)%> </td> <td> <%= Html.ValidationMessage("doc.Filetype_id")%> </td> </tr> <tr> <td> <%=Html.Label("Category")%></td> <td><%= Html.DropDownList("cat.parent_id", (IEnumerable<SelectListItem>)ViewData.Model.AllCategoriesList, "-please select item-", new { className = "unselected" })%> </td> <td><%= Html.ValidationMessage("cat.parent_id")%> </td> </tr> <% if (Session["TempFolder"] == null) { for (int i = 1; i < 6; i++) { %> <tr> <td> <%=Html.Label("Shot "+i.ToString()) %> </td> <td><input type="file" id="image_<%= i.ToString() %>" name="image_<%= i.ToString() %>" /></td> </tr> <% } }%> <tr> <td><input type="submit" value="save"/></td> </tr> </table> </form> </div>

    Read the article

  • Infragistics UltraWebTab

    - by user354089
    Im using Infragistcs UltraWebTab. The code is shown below ` <div class="tab-content"> <asp:Panel ID="PnlGeneral" runat="server"> <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tab-list"> <tr> <td style="border-bottom-color: White"> <asp:Label ID="LblErrors" runat="server" CssClass="ErrorMessage1"></asp:Label> <asp:Label ID="LblSuccessMsg" runat="server" CssClass="SuccessMessage1"></asp:Label> </td> </tr> <tr> <td> <table cellpadding="0" cellspacing="0" width="100%" border="0" class="tab-list"> <tr> <th width="205" class="FormLabel1"> Campaign Name <span class="ErrorMessage">*</span> </th> <td width="80%"> <asp:TextBox ID="TxtCampaignName" runat="server" CssClass="TextBox1"></asp:TextBox> </td> </tr> <tr> <th width="205" class="FormLabel1"> CRM Name <span class="ErrorMessage">*</span> </th> <td width="80%"> <asp:TextBox ID="TxtCRMName" runat="server" CssClass="TextBox1"></asp:TextBox> </td> </tr> <tr> <th class="FormLabel1"> Campaign Type <span class="ErrorMessage">*</span> </th> <td> <asp:DropDownList ID="DDLCampaignType" runat="server" CssClass="TextBox1" AutoPostBack="true" Width="117px" OnSelectedIndexChanged="DDLCampaignType_SelectedIndexChanged"> </asp:DropDownList> </td> </tr> <tr visible="false" id="trCompanyRow" runat="server"> <th class="FormLabel1"> Company <span class="ErrorMessage">*</span> </th> <td> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tr> <td class="style2" style="border-bottom-color: White"> <asp:DropDownList ID="DDLCompany" runat="server" CssClass="TextBox1" Width="117px" OnSelectedIndexChanged="DDLCompany_SelectedIndexChanged"> </asp:DropDownList> </td> <td class="style3" style="border-bottom-color: White"> <asp:LinkButton ID="btnlnknewCompany" runat="server" Style="font-size: 100%;" Text="Add New" OnClick="btnlnknewCompany_Click"></asp:LinkButton> </td> <td style="border-bottom-color: White"> <table cellpadding="0" cellspacing="0" border="0" width="100%" id="tdNewComapny" visible="false" runat="server"> <tr> <td class="style4" style="border-bottom-color: White"> <asp:TextBox ID="txtCompanyName" runat="server"></asp:TextBox> </td> <td style="border-bottom-color: White"> <asp:Button ID="btnCompanyAdd" runat="server" CssClass="btn1" Height="20px" Text="Add" Width="25%" OnClick="btnCompanyAdd_Click" /> </td> </tr> </table> </td> </tr> </table> </td> </tr> <tr id="trBannerImage" runat="server" visible="false"> <th class="FormLabel1"> Banner Image <span class="ErrorMessage">*</span> </th> <td> <asp:FileUpload ID="FileUploadBannerImage" runat="server" ToolTip="Add images for banner" /> </td> </tr> <tr> <th class="FormLabel1"> Start Date <span class="ErrorMessage">*</span> </th> <td> <asp:TextBox ID="TxtStartDate" runat="server" CssClass="TextBox1"></asp:TextBox><rjs:PopCalendar ID="CalStartDate" runat="server" Control="TxtStartDate" Format="dd mm yyyy" ShowErrorMessage="false" /> &nbsp;dd-mm-yyyy </td> </tr> <tr> <th class="FormLabel1"> End Date <span class="ErrorMessage">*</span> </th> <td> <asp:TextBox ID="TxtEndDate" runat="server" CssClass="TextBox1"></asp:TextBox><rjs:PopCalendar ID="CalEndDate" runat="server" Control="TxtEndDate" Format="dd mm yyyy" ShowErrorMessage="false" /> &nbsp;dd-mm-yyyy </td> </tr> <tr> <th class="FormLabel1"> Enabled? </th> <td> <asp:CheckBox ID="ChkEnabled" runat="server" /> </td> </tr> <tr style="border-bottom-color: White" id="tblVerificationFields" visible="false" runat="server"> <th style="border-bottom-color: White"> Company's Verification Fields </th> <td style="border-bottom-color: White"> <table border="0" cellspacing="0" cellpadding="0" class="tab-form" width="100%"> <tr> <td colspan="3" align="center"> <br /> <p> <label style="font-size: 14px; font-weight: bold; text-align: center;"> Select from existing verification fields below</label></p> </td> </tr> <tr> <td colspan="2"> <asp:Repeater ID="RptrVeriFieldsParamType" runat="server"> <HeaderTemplate> <table border="0" cellpadding="0" cellspacing="0" class="tab-grid" style="border: 0px"> <tr> <th> </th> <th> Field Name </th> <th> Type </th> <th> </th> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td style="border-bottom-color: White"> <asp:CheckBox ID="RptrChkVeriFields" runat="server" /> </td> <td style="border-bottom-color: White"> <asp:Label ID="RptrFieldName" runat="server" Text='<%# Eval("FieldName") %>'> </asp:Label> </td> <td style="border-bottom-color: White"> <asp:Label ID="RptrParamterTypeName" runat="server" Text='<%# Eval("PARAMETERTYPENAME") %>'> </asp:Label> </td> <td> <asp:Label ID="RptrHdnFieldId" runat="server" Text='<%# Eval("FIELDID") %>' Visible="false"></asp:Label> </td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> </td> </tr> <tr> <td style="border-bottom-color: White"> </td> </tr> <tr> <td> <table border="0" cellpadding="0" cellspacing="0" width="100%" runat="server"> <tr> <td colspan="6" style="border-bottom-color: White" align="center"> <br /> <p> <label style="font-size: 14px; font-weight: bold; text-align: center; width: 100%;"> Or Add New verification field</label> </p> </td> </tr> <tr id="trVerifcationFields" runat="server" visible="false"> <th style="border-bottom-color: White" width="110px"> <strong>Verification Name</strong> </th> <td style="border-bottom-color: White" width="50px"> <asp:TextBox ID="TxtVeriField" runat="server"> </asp:TextBox> </td> <th style="border-bottom-color: White" width="100px"> <strong>Parameter Type</strong> </th> <td style="border-bottom-color: White" width="100px"> <asp:DropDownList ID="DDLParameterType" runat="server"> </asp:DropDownList> </td> <th> </th> <td align="left" style="border-bottom-color: White"> <asp:Button ID="BtnAddVeriField" runat="server" CssClass="btn1" Height="20px" Text="Add" OnClick="BtnAddVeriField_Click" Width="75%" /> </td> </tr> </table> </td> </tr> </table> </td> </tr> </table> </td> </tr> <tr> <td> <table cellpadding="0" cellspacing="0" width="100%" border="0" class="tab-list"> <tr align="right"> <td> </td> <td align="right" class="tab-list"> <asp:Button runat="server" ID="Next" Visible="true" Text="Next >" CssClass="btn" /> </td> </tr> </table> </td> </tr> </table> </asp:Panel> </div> </ContentTemplate> </igtab:Tab> <igtab:Tab Text="CRM Deals (Step-2)" Key="Tab2"> <ContentTemplate> <div style="clear: both"> </div> <div class="tab-content"> <asp:Panel ID="PnlCRMDeals" runat="server" ScrollBars="Vertical" Height="500px"> <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tab-list"> <tr> <td> <asp:GridView ID="GridDeals" AutoGenerateColumns="False" runat="server" BorderStyle="none" BorderWidth="0" CellPadding="0" CellSpacing="0" GridLines="None" ShowFooter="false" HorizontalAlign="Left" CssClass="tab-grid" Width="100%"> <HeaderStyle CssClass="header" HorizontalAlign="Center" /> <PagerStyle CssClass="pager" /> <AlternatingRowStyle CssClass="odd" /> <Columns> <asp:TemplateField> <ItemStyle Width="5%" /> <ItemTemplate> <asp:CheckBox ID="ChkDeals" runat="server" Visible="true" /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Deal Name"> <ItemStyle Width="25%" /> <ItemTemplate> <asp:Label ID="DealName" runat="server" Text='<%# Eval("DealName") %>' /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Name in CRM"> <ItemTemplate> <asp:Label ID="CRMDealName" runat="server" Text='<%# Eval("CRM_NAME") %>' /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Deal Code"> <ItemTemplate> <asp:Label ID="PartNum" runat="server" Text='<%# Eval("PARTNUM") %>' /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </td> </tr> </table> </asp:Panel> </div> </ContentTemplate> </igtab:Tab> ` The problem im facing is after the "BtnAddVeriField" add button is clicked the Panel for the next tab gets displayed below the first tab's Panel. Furthermore, that Add button is not displayed as well.

    Read the article

< Previous Page | 12 13 14 15 16