C# - HTTPRequest.Files.Count Never Equals Zero?

Dec 10, 2010

I have a form on an HTML page that a user needs to use to upload a file which posts to an ASPX page. In the code behind, I want to test if a file has actually been loaded.

if (Request.Files.Count > 0)
{
DoStuff(Request.Files[0]);
}
else
{
throw new Exception("A CSV file must be selected for upload.");
}

I am never getting to the else. Is this just how ASP.NET operates? If I have a input element of type file, is it always going to upload a "file" even if one is not selected? What's the proper way to do this? Maybe this?

if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0)
{
DoStuff(Request.Files[0]);
}
else
{
throw new Exception("A CSV file must be selected for upload.");
}

View 3 Replies


Similar Messages:

DataSource Controls :: Select Statement Where Character Count Equals Specific Number?

Mar 22, 2010

Anyone know how to write a select statement to where it returns results that have a specific character count? I want to return all results that have 5 characters.

View 1 Replies

Web Forms :: Databound Item.Count Equals "1" On Page Load?

Mar 30, 2010

[I'm working in Microsoft Visual Studio 2005 with C# Language]There is a series of forms that I'm prepopulating with data from a SQL database. Every page that I've created in this way I've coded the needed information required into the method:protected void Page_Load(object sender, EventArgs e)and doesn't fire if it's a postback event.This latest form has a CheckBoxGroup that is databound and populates based on a table in the database. However, the form only prepopulates after a postback. Prior, the Item.Count says 1 when I know that there are 14 items. Again, it reads fine after the postback. I assume that this is because the CheckBoxGroup populates after the Page_Load function.Is there a way that I can make something like this fire during the Page_Load and not during the postback?

View 2 Replies

Unit Testing - Mocking HttpRequest In .NET 4.0 / HttpRequest Is Sealed With No Interface

Jul 15, 2010

I'm writing unit tests in ASP.NET 4.0 web application (ASP.NET Forms, not MVC). There are several spots in the code where I call the ServerVariables collection to call variables like REMOTE_ADDR. Since my unit tests do not actually initiate HttpRequests when executing my code, things like ServerVariables are Null and therefore error when I try to call HttpContext.Current.Request.ServerVariables("REMOTE_ADDR")

All the solutions I've found to address this issue refer to MVC and so they assume that HttpRequest derives from HttpRequestBase, which it does in MVC but not in ASP.NET Forms.I tried using Moq but you can't mock a sealed class, and HttpRequest is unfortunately sealed with no interface.

View 1 Replies

How To Count Files In The Folder

May 18, 2010

I want to count number of mdb file in the folder.The folder contains both mdb and ldb files.I want to count only *.mdb files.How to perform count operation.But i am use the following code.It gives total counts.

files = Directory.GetFiles(Apppath + "/backup/");
numFiles = files.Length;
int flname = numFiles + 1;

View 8 Replies

C# - The Best Way To Count Words In PDF Files?

May 24, 2010

i am currently using microsoft Interop.Dsofile.dll to count words in office word doc and docx files and also the methods from Microsoft.Office.Interop.Word.dll is handy and can be another solution. what about PDF files? is there any free or commercial API ,DLL , component or any solution to count words ,paragraphs and lines in pdf files ?

View 1 Replies

Count Number Of Files After Uploading?

Sep 27, 2010

im hope i can make sense to this post cause i dont have an idea where to begin :-) I have some files upload code so the user can upload files to the server (it can be 1 or 5 or 20 files). the code is working fine, and the files uploading to the folder on the server. The problem is, that after the files uploads i need to display to the user some textboxes to every file (like: number of copies, if its color or b/w, the print size etc). is there some way, after the files is uploaded, to show the user the name of the files and for each file name to display some textboxes (like: to count the number of files and then display the names and few same textboxes for each file),

View 13 Replies

SQL Server :: Select N Rows Whose Sum Is Equals To 10

Aug 9, 2010

I want to build a select query on the below resultset

[Code]....
[Code]....

The query will select the first n rows whose quantity is equals to the sum of my provided value i.e. 10

Now in the case of providing the value 10 the first 3 rows will select as the sum of 5,4, and 1 is equals to 10.

View 1 Replies

Get Gridview Column Name With Autogenerate Equals To True

Oct 27, 2011

I am trying to retrieve a column name from an autogenerated gridview. I want to test for a field name (if FieldName = "whatever" then do something) The major problem is that indexes and field names are all sort of locked away when you auto generate your gridview (autogenerate = true) Unfortunately since I am using the gridview to display the results of different queries (different number of columns and column types) changing auto generate is not an option.

The question is, based on what I have got so far how would I capture a field/column name. I figured out how to get the column index but am stuck on the column name.

Code:
Protected Sub GridViewList_RowDataBound(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _
Handles GridViewList.RowDataBound

Dim vColumnCnt As Integer = -1
For Each vCell As TableCell In e.Row.Cells 'GridViewList.Rows(0).Cells
vColumnCnt = vColumnCnt + 1
Next

e.Row.Cells(vColumnCnt).Text = Server.HtmlDecode(e.Row.Cells(vColumnCnt).Text)
End Sub

View 15 Replies

Web Forms :: Display A Modal On Submit But Only If A Dropdownlist Equals?

Nov 11, 2010

I have a form that on submits displays a modal-popup window, but I only want to display this modal if a particualr choice has been made within a Drop Down List (DDLTermination)

I'm not sure how link it up, into the submit button

so far I've got the following within the submit button but this isn't working how I want:

[Code]....

View 2 Replies

Web Forms :: MyFileInput.PostedFile.ContentType Equals Null?

Nov 1, 2010

Simple upload has been working for quite a while now, yet it seems to all the sudden not work (but only for specific file types). mp3 can upload, flv cannot (remember, this was all working before).After a little debugging, I discovered that a portion of my code is never being entered because I test something first:

[Code]....

I have discovered that resourceMediaFile.PostedFile is not null, resourceMediaFile.PostedFile.ContentLength is the correct size for the uploaded file, yet resourceMediaFile.PostedFile.ContentType is now null. I've literally had this work over 1,000 times with several files (including the one I'm testing with) and it consistently came back "application/flv".

What would cause ContentType to be null if the other attributes are not?

View 3 Replies

.NET HttpRequest From 1.1 To 3.5?

Jan 12, 2010

We have to ASP.NET applications, one in 1.1 and one in 3.5. In order to log our errors in the same location we are going to create a WebService that the 1.1 app can call. If I include an HttpRequest as one of the parameters to the webservice, will there be a versioning problem?

View 1 Replies

UrlRewriting.Net Module + IIS7 Equals Page.User == Null?

Jan 8, 2010

I've used the UrlRewriting.Net module for a couple years now without any problems in Windows XP and Windows 2003. I just recently upgraded my home PC to Windows 7 and started developing a new website.The plan was to use .html extensions and rewrite them to their .aspx counterparts using the UrlRewriting.Net module. Everything works flawlessly in VWD 2008, but when I try running it through IIS7 it is a different story.

When I try to access a page via the .html rewrite I can no longer access Page.User; it keeps returning null. If I hit the page using it's .aspx extension, Page.User is correctly populated. I should also mention that I have a LoginView controller in my Master Page and it suffers from the same symptoms: When accessing via .html extension it shows the AnonyousTemplate; When using .aspx extension it properly shows the LoggedInTemplate. I'm guessing the two are related.

[Note: I've also tried extensionless URLs and they exhibit the same problem]

The only way I've gotten it to work is to switch the application pool to Classic, which then requires me to add an ASP.Net ddl handler for the .html extension [otherwise it is handled by the StaticFileHandler and comes up as a 404 error]. However, I'd like my web app to run properly for people without having to fiddle around with IIS.So I am left with several questions:Does anyone have ideas as to why Page.User always equals null for .html => .aspx rewritten pages?

Why does it work in VWD 2008, but not IIS7?

What changed from IIS6 => IIS7 that could have caused this?

[Note: I just tried a .aspx => .aspx rewrite and it did not exhibit the problem. Not really what I want, but thought I should mention it.]

View 2 Replies

Forms Data Controls :: GridView_RowUpdated Event The E.OldValue.count E.NewValue.Count

Jun 4, 2010

In the GridView_RowUpdated event the e.OldValues.count <> e.NewValues.Count. 1 out of 5 columns has been converted to a template field.

View 9 Replies

Forms Data Controls :: Gridview Row Count / How To Get A Count Of The Number Of Rows That Are Returned

Dec 17, 2010

When a user submits the query to SQL when clicking a button I need to get a count of the number of rows that are returned. Which event does the gridview.count code need to be place in?

Right now I have it in the btn_click event, but in order to get it to count the rows you have to hit the button twice since the query is not returned yet. Here is my code.

[Code]....

View 1 Replies

How To Get Host Name Without Using HttpRequest

Jan 29, 2010

I'm want to run a "background job" in my ASP.NET application (periodically, as separate thread). And I need host name (DNS name or IP) to do my tasks. The problem - HttpContext.Current may be not available here (it's NULL).

Is there any way to get a host name in not using HttpContext.Current.Request.Url.Host.

View 3 Replies

Data Controls :: Display Total Row Count And Count Of Specific Types In Label In GridView

Oct 5, 2012

I HAVE A GRID VIEW IN asp.net + VB Code. There is a drop down list and the selected data is displayed in web page. I placed a label in web page and code behind i used following code.

Protected Sub GridView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.DataBound
Label1.Text = GridView1.Rows.Count.ToString()
Dim ONYO As Integer = 0
Dim DONE As Integer = 0
For i As Integer = 0 To GridView1.Rows.Count - 1
If GridView1.Rows(i).Cells(0).Text = "ON YO" Then

[Code] .....

View 1 Replies

ADO.NET :: FieldTemplate_Edit To Show Value When Custom Meta Data Is Set Editable Equals False?

Aug 28, 2010

Have a custom FieldTemplate (RadioButtonChooser_Edit.ascx) that shows a radiobuttonlist based on a single character. Using LinqtoSQL/DynamicData enabled.

Example G, F, P (Good, Fair, Poor).

If the custom metadata for a field in the table is set [Editable(false)] I get a G, F, or P. I would like to show the full word when editable is set to false. Not sure how to approach this.

View 1 Replies

DataSource Controls :: Select Images Where Parent Id Equals Highest Pieces Id?

Jan 7, 2010

This obviously isn't right but I think best describes what I'm trying to do:

SELECT ImagesLge.MainImages
FROM pieces
INNER JOIN ImagesLge
ON ImagesLge.ParentId = pieces.ID
"WHERE pieces.ID = MAX(pieces.ID)"

View 2 Replies

C# - How To Queries Are Sent Back In An HttpRequest

Aug 11, 2010

I'm going to try to use the WebClient object in .NET to grab the response querystring values sent back by the resource.

I'm familiar with grabbing xml, json, etc. but typically I haven't worked with many NVP type of APIs in terms of grabbing the query immediately from an response sent back from a resource server-side. So how is a query sent back, in the body of a response, header, what? How do you grab it, with the stream object just like you do anything else? This questions relates to the environment I work in C# but really it relates to the web as a whole as well which is why I tagged this in multiple categories as a Request/Response is not MS specific however I am also at the same time trying to utilize the .NET WebClient object.

View 1 Replies

Jquery - Get HttpRequest With A Web Method?

Oct 1, 2010

I have a page web method, and I need to get access to the headers, and particularly the uploaded files. Is this possible? Can a web method receive a file?If not, what would you recommend to upload files without post back? I am using the jQuery forms library that has support for this (and I have had it working with Django), however, I am having a hard time finding answers on how to do this with ASP.NET.

View 2 Replies

Populating HttpRequest.Browser Properties?

Jan 7, 2010

I'm creating HttpContext "by hands" (see [URL]. Does somebody know how can I populate HttpRequest.Browser class's properties (the HttpRequest.Browser.Browser one)? Unfortunately, the HttpBrowserCapabilities class has no the appropriate setter and adding the corresponding http header to the request gives no result.

View 1 Replies

Vb - HttpRequest Maximum Length Exceeded In ASP

May 18, 2010

I'm trying to fix an issue with an application I'm supporting (I didn't write the code). The code takes an SSRS report and renders it in pdf format. Users are sporadically getting the error indicated in the title. There is no rhyme or reason to when the error is generated (a particular report will run one time and throw the error the next). The code is below.

Public Sub OpenReport()
Dim MyParms As New Generic.List(Of ReportParameter)
Dim mimeType As String = Nothing
Dim encoding As String = Nothing
Dim extension As String = Nothing
Dim deviceInfo As String = Nothing
Dim streamids() As String = Nothing
Dim warnings As Microsoft.Reporting.WebForms.Warning() = Nothing
Dim bytes() As Byte
Dim format As String = "PDF" ''#to open the report in pdf; report viewer invisible
Try
If dropReports.SelectedItem.Value = "1" Then
If Session("IsBDAP") = True Then
MyParms.Add(New ReportParameter("SCAId", dropSCA.SelectedItem.Value, False))
Else
MyParms.Add(New ReportParameter("SCAId", Server.UrlEncode(Session("SCAId")), False))
End If
MyParms.Add(New ReportParameter("ProviderId", dropProvider.SelectedItem.Value, False))
If dropVisit.Visible = True Then
MyParms.Add(New ReportParameter("VisitId", dropVisit.SelectedItem.Value, False))
End If
MyParms.Add(New ReportParameter("FY", dropContractFY.SelectedItem.Value, False))
ReportViewer1.ProcessingMode = ProcessingMode.Remote
ReportViewer1.ServerReport.ReportServerUrl = New Uri(System.Configuration.ConfigurationManager.AppSettings("ReportServerURI"))
ReportViewer1.ServerReport.ReportPath = Session("ReportsFolder") & "MReport"
ReportViewer1.ServerReport.ReportServerCredentials = New MyReportServerCredentials()
ReportViewer1.ServerReport.SetParameters(MyParms)
''#Code to convert the report to pdf
deviceInfo = "<DeviceInfo>" + "<SimplePageHeaders>True</SimplePageHeaders>" + "</DeviceInfo>"
bytes = ReportViewer1.ServerReport.Render(format, deviceInfo, mimeType, encoding, extension, streamids, warnings)
Dim size As Integer = bytes.Length
ReportViewer1.ServerReport.Refresh()
Response.Buffer = True
Response.Clear()
Response.ContentType = mimeType
Response.AddHeader("content-disposition", "attachment; filename=MReport." + extension)
Response.BinaryWrite(bytes)
ElseIf dropReports.SelectedItem.Value = "2" Then
If Session("IsBDAP") = True Then
MyParms.Add(New ReportParameter("SCAId", dropSCA.SelectedItem.Value, False))
Else
MyParms.Add(New ReportParameter("SCAId", Server.UrlEncode(Session("SCAId")), False))
End If
MyParms.Add(New ReportParameter("ProviderId", dropProvider.SelectedItem.Value, False))
If dropVisit.Visible = True Then
MyParms.Add(New ReportParameter("FollowUpVisitId", dropVisit.SelectedItem.Value, False))
End If
MyParms.Add(New ReportParameter("FY", dropContractFY.SelectedItem.Value, False))
ReportViewer1.ProcessingMode = ProcessingMode.Remote
ReportViewer1.ServerReport.ReportServerUrl = New Uri(System.Configuration.ConfigurationManager.AppSettings("ReportServerURI"))
ReportViewer1.ServerReport.ReportPath = Session("ReportsFolder") & "FReport"
ReportViewer1.ServerReport.ReportServerCredentials = New MyReportServerCredentials()
ReportViewer1.ServerReport.SetParameters(MyParms)
''#Code to convert the report to pdf
deviceInfo = "<DeviceInfo>" + "<SimplePageHeaders>True</SimplePageHeaders>" + "</DeviceInfo>"
bytes = ReportViewer1.ServerReport.Render(format, deviceInfo, mimeType, encoding, extension, streamids, warnings)
ReportViewer1.ServerReport.Refresh()
Response.Buffer = True
Response.Clear()
Response.ContentType = mimeType
Response.AddHeader("content-disposition", "attachment; filename=FReport." + extension)
Response.BinaryWrite(bytes)

I read that the default length limit is 4MB. None of the reports by themselves are even over 350K. I'm wondering if this could be caused by a caching issue. I'm not an expert, so I need some guidance as to how best to solve the problem. I also want to understand why the issue is happening. note that only 2 reports are shown in the snippet - there are about 30+ reports in the full sub. edit - I tried the proposed solution, but it didn't help (I also tried the Fiddler route, but did not see anything glaring). I thought it might be best to clarify. The reports will run fine for a while, but the execution time gradually gets slower and slower until the application eventually displays the error.

View 3 Replies

Difference Between HttpMethod And RequestType Of HttpRequest?

Jan 28, 2010

The HttpRequest class defines two properties:

HttpMethod:

Gets the HTTP data transfer method (such as GET, POST, or HEAD) used by the client.
public string HttpMethod { get; }
The HTTP data transfer method used by the client.

and RequestType:

Gets or sets the HTTP data transfer method (GET or POST) used by the client. public string RequestType { get; set; } A string representing the HTTP invocation type sent by the client.What is the difference between these two properties? When would i want to use one over the other? Which is the proper one to inspect to see what data transfer method was used by the client?The documentation indicates that HttpMethod will return whatever verb was used: such as GET, POST, or HEAD while the documentation on RequestType seems to indicate only one of two possible values: i test with a random sampling of verbs, and both properties seem to support all verbs, and both return the same values:

Testing:

Client Used HttpMethod RequestType
GET GET GET
POST POST POST
HEAD HEAD HEAD
CONNECT CONNECT CONNECT
MKCOL MKCOL MKCOL
PUT PUT PUT
FOOTEST FOOTEST FOOTEST

What is the difference between:

HttpRequest.HttpMethod
HttpRequest.RequestType

and when should i use one over the other? Keywords: iis asp.net http httprequest httphandler

View 2 Replies

Get The Raw Response Header And Body From The HttpRequest?

Feb 18, 2010

Is there a way to get the raw response header and body from the HttpRequest.Response object for debugging when issues arrise?

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved