|
Hi,
I wanna to have a webservice in aspnet (C#) that :
select * from tableName (OR call Stored Procedure)
and save the result in Text file and finally zip that and delete that text file !
Thanks in advanced !
|
|
|
|
|
And what is your problem?
Use the best guess
|
|
|
|
|
Hi
Dont know how to start and can webservice do that ?
Do you have any example ?
Thanks in advnaced!
|
|
|
|
|
jojoba2011 wrote: Dont know how to start Then you need to read some books, tutorials etc.
jojoba2011 wrote: can webservice do that ? Do what exactly?
Please think about what problem you are trying to solve and give us some clear information about what is not working.
Use the best guess
|
|
|
|
|
Hi,
Thanks a lot!
I am writting an app (android with C#) and the program is :
it have update button for updating database in mobile.
so i wanna do something that get data from sql server 2008 (in host - Internet ) and update my mobile sqlite database.
thanks in advanced @
|
|
|
|
|
jojoba2011 wrote: so i wanna do something that get data from sql server 2008 Then you need to write some SQL commands to extract the data and format it into whatever output you require. There are many resources, both here in the Articles Section[^] and in the wider internet that Google can find, that will help you.
Use the best guess
|
|
|
|
|
I have an interesting issue; I have been tasked with building a "one size fits all" file upload page. I am using C# and the 4.5 framework, so my options are wide open, but I have one problem in particular...
Part of the requirement involves an old upload page; we already have a page that uses a regular file upload control with a button and it works exactly as expected. Here's what I need to do; the page I need to build needs to access the old page in the background and do the following:
Upload the selected file
Return the message displayed by the old page
So I need to build a page that allows the user to select a file and "upload" it by accessing the older page in the background and pass the file and/or file information to it. I do not have access to the code of the old page, so I have to use the new page to handle all of the work.
So far I have played with code I have found using HttpWebRequest,WebClient and even the .net libraries for cURL with no success. Has anyone tackled something similar in the past? Any suggestions?
______________________
Oh Hamburgers!
|
|
|
|
|
Vodstok wrote: Return the message displayed by the old page
What is the message, why is it so important.
|
|
|
|
|
The new page is being built to integrate two old pages into a new interface, so for end users accustomed to the old functionality, they want to be able to present them with the message(s) that the old one did to minimize the changes in how they see things. Basically, it's out of my hands why, it's in the spec so I have to.
There is a new solution in the works, but for the time being, I am tasked with making a new page that "operates" the old page in the background.
______________________
Oh Hamburgers!
|
|
|
|
|
Richards idea is a good one.
I've used the http in a file upload for ckEditor, and it's pretty slick.
Would like to know if it's works out, keep me up to date.
|
|
|
|
|
Is the old page written in ASP.NET? If so, you'll probably have to issue a GET request first, find the hidden view-state and event validation fields, and include those fields in your POST request.
Once you've got the data you need to send, you'll need to build and send a multipart/form-data request. Unfortunately, there's no built-in way to do that prior to .NET 4.5, but there are quite a few examples floating around for earlier versions. Eg: UploadFileEx: C#'s WebClient.UploadFile with more functionality[^]
If you're using .NET 4.5, you can use the new HttpClient[^] class from the System.Net.Http[^] assembly, combined with the MultipartFormDataContent[^] class.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Excellent, I have definitely been missing that detail, Richard. I will give it a shot and let you know how it works
______________________
Oh Hamburgers!
|
|
|
|
|
Okay, so I have a question; I am doing a get, scraping out the event validation and viewstate to send back, but when I try to post back to the page, I am getting what appears to be a non-posted page on the other end.
Since I can't seem to reuse the original request, the page I get has different viewstate information, so I'm not getting the post I hoped (I think that is what is happening anyway). I am definitely hitting the page; I am doing a Response.Write for the returned content and it is definitely loading the correct page in the background.
I seem to be back at square one (albeit using the baked-in features of 4.5, which is nice ). So I am definitely calling the right page, but it does not appear to actually post.
Here is the code I am using:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(@"http://localhost:51749/Default.aspx");
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
HttpWebResponse resp = (HttpWebResponse)request.GetResponse();
string respString = string.Empty;
using (Stream strm = resp.GetResponseStream())
{
using (StreamReader sr = new StreamReader(strm))
{
respString = sr.ReadToEnd();
}
}
request = (HttpWebRequest)HttpWebRequest.Create(@"http://localhost:51749/Default.aspx");
List<string> controls = respString.Split('\n').Select(o => o.Replace("\r", string.Empty).Trim()).Where(o => o.StartsWith("<input") && o.IndexOf("hidden") > -1).ToList();
request.Method = "POST";
request.ContentType = "multipart/form-data";
using (HttpClient client = new HttpClient())
{
using (MultipartFormDataContent content = new MultipartFormDataContent())
{
var values = new[]
{
new KeyValuePair<string, string>("txtFile", "BALHHHHH"),
new KeyValuePair<string, string>("fu1", fileName),
}.ToList();
foreach (string cont in controls)
{
List<string> attributes = cont.Split(' ').Where(o => o.ToLower().StartsWith("id") || o.ToLower().StartsWith("value")).Select(o => o.Replace("\"", string.Empty)).ToList();
string id = attributes.Where(o => o.ToLower().StartsWith("id")).FirstOrDefault().Split('=')[1];
string value = attributes.Where(o => o.ToLower().StartsWith("value")).FirstOrDefault().Split('=')[1];
values.Add(new KeyValuePair<string, string>(id, value));
}
foreach (KeyValuePair<string, string> keyValuePair in values)
{
content.Add(new StringContent(keyValuePair.Value), keyValuePair.Key);
}
ByteArrayContent fileContent = new ByteArrayContent(File.ReadAllBytes(fileName));
fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = Path.GetFileName(fileName)
};
content.Add(fileContent);
string requestUri = "http://localhost:51749/Default.aspx";
HttpResponseMessage result = client.PostAsync(requestUri, content).Result;
using (Stream res = await result.Content.ReadAsStreamAsync())
{
byte[] bres = new byte[res.Length];
res.Read(bres, 0, bres.Length);
Response.Write(Encoding.ASCII.GetString(bres));
}
}
}
I think at this point any suggestion would be a good one. I was using older techniques before and achieving the same thing, and Richard's suggestion seems to be the first thing I have encountered that offered a solution as to why what I was doing before wasn't working, so I suspect something in here is to blame.
______________________
Oh Hamburgers!
|
|
|
|
|
Based on a quick test I did last night, I came to the conclusion that the Name of each part needs to be enclosed in quotes:
foreach (KeyValuePair<string, string> keyValuePair in values)
{
content.Add(new StringContent(keyValuePair.Value), "\"" + keyValuePair.Key + "\"");
}
Without this, ASP.NET doesn't think there's a form present.
(I'm not sure if this is a bug in ASP.NET, a bug in the HttpClient implementation, or a misunderstanding on my part.)
You'll need to specify the name for the file content, which should be equal to the name of the FileUpload control on the target page.
I also found that if the FileName isn't enclosed in quotes, ASP.NET request validation rejects the request:
ByteArrayContent fileContent = new ByteArrayContent(File.ReadAllBytes(fileName));
content.Add(fileContent, "\"nameOfTheFileUpload\"", "\"" + Path.GetFileName(fileName) + "\"");
You're missing an await on the client.PostAsync line, but I presume that's just a typo.
You can also replace the ReadAsStream + Read + Encoding.ASCII.GetString block with a simple await response.Content.ReadAsStringAsync() call.
If all else fails, you can always trace the request with Fiddler[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Most excellent, I am not quite there yet, but considering all of the annoying viewstate errors I am now getting (I appear to need the same machine key for both test sites) I am definitely getting farther than I was. I will update as soon as I get it figured out. Thank you again! This has been a huge help.
______________________
Oh Hamburgers!
|
|
|
|
|
The plot thickens. The page I will eventually have to call is written in JSP, which is of no immediate concern since the basic idea behind this requirement doesn't change, but here's where it gets interesting; the page I am calling uses JavaScript to set the cookies, and the page login immediately fails unless it's executed.
So I'm not only not back to square one, it's not even on the horizon right now. Gotta love legacy products...
______________________
Oh Hamburgers!
|
|
|
|
|
Hi,
Please suggest me the links for the best books or videos for ASP.Net MVC 4.
Thanks
|
|
|
|
|
|
|
I am starting to make my first steps in the asp.net world.
I run into something that wasn' t new to me, though its use in asp.net is something that to me seems totally different from what i knew before.
I'm talking about the "runat=server" clause. Remembering classic asp, vbscript, I learned that "runat=server" was used to instruct the web server to elaborate the vbscript code subject to the clause itself, rather than send it to the client.
In asp.net, it seems to be different. I read that it's used for "server side control" , that is, controls which are "run" on the server side. This is nonsense to me . How can a control be run on the server side, given that the server side obviously doesn't have a Gui (and if it has, probably it has nothing to do with the user session) ....? my suspicion is that a "server side" control, means a control which can be dealt with by a server side script or code behind snippet. But ... is this the right idea ?
I read tons of documentation and articles but it seems none of them wants to be clear about this subject. I wonder how the documentation can be so fuzzy ... don't these guys ever ask themselves such simple questions ? Do they always take things for granted ?
|
|
|
|
|
You are right, runat=server means the control is executed on server. Each control with such attribute is processed before page is ready to send to user and as a result only output html is visible for user, not the source code.
To be honest, I never thought about it in your way. It was always like that - if you want your code executed use runat=server. So it may be the reason why it isn't explained much.
--
"My software never has bugs. It just develops random features."
|
|
|
|
|
By using runat="server", controls are enhanced to enable server side processing.
It means, you will be able to access the control and its properties on server side too. Without runat="server", you won't be able to access the control on server side (code behind file).
It's not about GUI. It's about accessibility to the object and it's properties.
|
|
|
|
|
To elaborate on Sandeeps explanation a little more,
ASP.Net objects can be used on a web form, that uses combinations of just plain old HTML and ASP.Net Objects such as the panel control.
So you can do it 2 ways, 1 in straight HTML or 1 as an asp.net object
<div style="float: left;"></div>
or
<asp:panel id="panel1" runat="Server" ></asp:panel>
Now you can also create that object in code behind, or pure code
Dim panel_Container as Panel = new panel
with panel_container
.style.add(HtmlTextWriterStyle.float, "left")
end with
controls.add(panel_container)
I don't know what the exact description is of using runat="Server" is, but I know you need it when using system.web objects on the web form, which is a .aspx page. The server will convert that object to HTML, and send the HTML back to the browser.
So a Panel object is a set of div tags, a label is a span tag.
I came from vb and asp classic and went to asp.net, and thought that all the elements on a webform has to be a asp.net object, but over the years, I learned how to better manage my time and produce consistent looking products by keeping asp.net objects to a minimum now.
I just use straight HTML now, and only use asp.net object for things like master pages, or anything I need to interact with in code behind on the server side. I never us the object font attributes or colors anymore, and use CSS for that.
In my opinion, don't get too crazy using the asp.net objects in the beginning, and just use html and CSS. As you start writing more code, then you can go back and convert some HTML to objects when needed.
|
|
|
|
|
we know that default session timeout is 20 minutes. so i just like to know if some one stay idle for 20 minute then session will be timeout?
if some one works for 20 minutes then session will not expire ? if will expire then when expire.
i hard that session has sliding expiration nature. can anyone tell me how sliding expiration works. is it default behaviour or developer has to set anything for club up this sliding expiration with session.
please discuss the internal of session nature & expiration. thanks
tbhattacharjee
|
|
|
|
|
Tridip Bhattacharjee wrote: i hard that session has sliding expiration nature. can anyone tell me how sliding expiration works
Pretty simple really. If the user doesn't re-access the application before the timeout, their session will expire. Theoretically as long as the user keeps accessing the app before the timeout, the "clock restarts" and the session would never expire, as soon as they wait until after the timeout their session will expire. It is also possible for the application to close the session if needed.
Tridip Bhattacharjee wrote: Is it default behaviour or developer has to set anything for club up this sliding expiration with session.
This is the default, you don't have to do anything extra.
|
|
|
|
|