|
I create a web page with asp.net using visual.studio. And I need to acquire data from my website and save it to my computer, in a particular folder. How can I do this? Should I write this part of the program in 'Site.Master.cs' or can you tell me more exactly what I have to do, please?
NetworkAcquisitionDevice device = new NetworkAcquisitionDevice("100.0.0.1",51212,30);
FrameSearcherSecond frameSearcher = new FrameSearcherSecond();
FormatterXorByte formatterCust = new FormatterXorByte();
DataAcquisition daq = new DataAcquisition(device, frameSearcher, formatterCust);
daq.EnableDataFormatting(true);
daq.EnableFrameSearching(true);
daq.EnableDataWriting(true); // data wil be in your harddisk.
daq.StartAcquisition();
bool stop =false;
while (!stop)
{
byte[] dataFromDevice= daq.GetData();
//process data here
}
daq.StopDataAcquisition();
daq.Reset(); // it will reset all parameters.
|
|
|
|
|
I do not understand where you are stuck.
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I have a web application where I have a template (word) which I need to open/save and replace some values at run time. How do I do this?
|
|
|
|
|
|
If it's a new-format file (.docx ), then you'll need to use something like DocX[^] or the Open XML SDK 2.5 for Office[^].
If it's an old-format file (.doc ), then you'll struggle to find a non-commercial library to manipulate it.
NB: Don't be tempted to try Office Interop; aside from needing an Office license for your server, it's not supported in ASP.NET:
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Below is my code. I can't figure out how to find specific text and replace it
Dim byteArray As Byte()
Dim myDataTable As DataTable = objDB.GetTemplates(plan.YearCode, "Templates", plan.State)
If Not myDataTable Is Nothing AndAlso myDataTable.Rows.Count > 0 Then
byteArray = DirectCast(myDataTable.Rows(0).Item("Template"), Byte())
Else
Throw New Exception("Unable to retrieve the specified template")
End If
Using mem As MemoryStream = New MemoryStream
mem.Write(byteArray, 0, CInt(byteArray.Length))
Using doc As WordprocessingDocument = WordprocessingDocument.Open(mem, True)
??? How do I find specific word and replace it
Helper.DownloadStream("Schedule" &" .docx", mem, Helper.WORD_CONTENT_TYPE)
End Using
End Using
|
|
|
|
|
|
I've given reference in project.json file , but when i am adding namespace in cs file , it is populating issue saying this file doesn't exist. but also when i am running this project by command prompt (dotnet run ) it is working fine , but using Visual Studio it is throwing errors for namespace.
|
|
|
|
|
Giving the reference does not ensure that the latest dependencies are resolved or not. To resolve the latest dependency changes, you need to run the restore command,
$ dotnet restore
Visual Studio does that all itself in the background, can you tell me which version of Visual Studio you are using? Things got changed a lot in Visual Studio 2015 and Visual Studio 2017 — Visual Studio 2017 is based on csproj, project.json and its content doesn't matter at all there.
What is .csproj file?
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
here's the problem
I've got an API with the following address (HTTP post)
http:
"headers": {
"accept": "application/json",
"content-type": "application/x-www-form-urlencoded"
},
"data": {
"username": "mrkeivan",
"password": "09126101185",
"uiId": "d960a994-0972-44ba-ae2c-2c3a01e135c1"
}
I need to call this api in another website and a mobile application, to do so I enabled Asp.net APi Cores globally in web config and WebApiConfig.cs
**in WebApiConfig.cs**
config.EnableCors(new EnableCorsAttribute("*", "*", "*"));
> as well as Web.config
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="POST, PUT, DELETE, GET, OPTIONS" />
<add name="Access-Control-Allow-Headers" value="content-Type, accept, origin, X-Requested-With, Authorization, name" />
<add name="Access-Control-Allow-Credentials" value="true" />
</customHeaders>
</httpProtocol>
when I call this in postman, it works perfectly
however when I call it through an ajax method or a friend of mine calls it in his mobile app project it returns the following error
> XMLHttpRequest cannot load
> http://api.novin.solutions/api/member/login. Response for preflight
> has invalid HTTP status code 404 OPTIONS
> http://api.novin.solutions/api/member/login 404 (Not Found)
I have read many articles in this matter and applied all the suggestions, but nothing fixed my problem
any help would be appreciated
|
|
|
|
|
When I made a call to that api this is the response I got
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Vary: Accept-Encoding
Server: Microsoft-IIS/8.5
Access-Control-Allow-Origin: *
Access-Control-Allow-Origin: *
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-Powered-By-Plesk: PleskWin
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST, PUT, DELETE, GET, OPTIONS
Access-Control-Allow-Headers: content-Type, accept, origin, X-Requested-With, Authorization, name
Access-Control-Allow-Credentials: true
Date: Thu, 09 Mar 2017 10:02:31 GMT
Content-Length: 135
Note that there are multiple "Access-Control-Allow-Origin" headers. The first thing I would do is look to why that is happening and get it down to one as the browser may well reject the response as invalid (if I use IE I get an error in the console explicitly stating there are duplicate headers). This is probably happening as you are configuring it in multiple places.
|
|
|
|
|
Hi, thanx for the response
removed them, now I only have it in
- web.config and
- config.EnableCors(); in WebApiConfig
|
|
|
|
|
Now there are two
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Vary: Accept-Encoding
Server: Microsoft-IIS/8.5
Access-Control-Allow-Origin: *
Access-Control-Allow-Origin: *
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-Powered-By-Plesk: PleskWin
Date: Thu, 09 Mar 2017 11:15:52 GMT
Content-Length: 135
You only need it defined once, but you are defining it in two config files
|
|
|
|
|
How do you make this call ???
|
|
|
|
|
Via ajax and I use Fiddler to examine the response
$(document).ready(function () {
$.ajax({
type: "POST",
url: "http://api.novin.solutions/api/member/login",
data: {
"username": "mrkeivan",
"password": "09126101185",
"uiId": "d960a994-0972-44ba-ae2c-2c3a01e135c1"
}
}).done(function (data) {
alert(data);
}).fail(function (jqXHR, textStatus) {
alert("Request failed: " + textStatus);
});
});
|
|
|
|
|
you are right, i found out a line I left in the global.cs
thanx man, appreciate it.
|
|
|
|
|
this is what I get
Request
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:cache-control
Access-Control-Request-Method:POST
Cache-Control:no-cache
Connection:keep-alive
Host:api.novin.solutions
Origin:http://localhost:1344
Pragma:no-cache
Referer:http://localhost:1344/Home/Index
User-Agent:Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
Response
Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:content-Type, accept, origin, X-Requested-With, Authorization, name
Access-Control-Allow-Methods:POST, PUT, DELETE, GET, OPTIONS
Access-Control-Allow-Origin:*
Connection:close
Content-Length:1245
Content-Type:text/html
Date:Fri, 10 Mar 2017 05:26:20 GMT
Server:Microsoft-IIS/8.5
Vary:Accept-Encoding
X-Powered-By:ASP.NET
X-Powered-By-Plesk:PleskWin
|
|
|
|
|
If that's your real password that you've just posted on a public forum, I hope it doesn't provide access to any sensitive data, and that you're going to change it as soon as the problem is resolved.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
))) don't worry it's a sample ! 
|
|
|
|
|
hello everyone
currently i am doing a project on XSS(Cross Site Scripting) prevention, for that i want to process a small text paragraph, contain text and java code.
example-
The Conjuring 2 is a mixed bag of a movie.....That being said, if you are someone that doesn't mind jump scares, you will most likely eat this movie up!<..........some java code here...........>
i want to separate out the text code present in between "<" and ">" so that i can process it separately.
thank you for your help.
|
|
|
|
|
You could use a regex or the DOM model to find the specific tags you are interested in.
|
|
|
|
|
|
Back for more help, sorry.
After all that struggle to get my project working in php, they came back on Wednesday last week that they could not use current project written in php because the wordpress theme that the php would be integrated with is not set up correctly to allow us the ability to upload the file as a template and we could gain access to MySQL database.
So, I had to start all over building the app in asp.net.
I have been working on this since Wednesday last week.
For the most part, I think I got most it working. I was able to rewrite the dynamic row addition.
I am currently trying to use JSON object with an ajax call to submit the records into the database.
The issue right now, however, is that I get, my custom error message which says, "Error while inserting data".
Sorry for the long code. I am posting them because I am not sure what is causing the error, whether it is coming from my HTML markup or codefile.
Any ideas, as always, is greatly appreciated.
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$(document).on("click", "#btnAdd", function () {
var rowCount = $('.data-contact-person').length + 1;
var contactdiv = '<tr class="data-contact-person">' +
'<td><input type="text" style="width:200px;" name="sourcename' + rowCount + '" class="form-control sourcename01" /></td>' +
'<td><input type="text" style="width:200px;" name="sourceaddress' + rowCount + '" class="form-control sourceaddress01" /></td>' +
'<td><input type="text" style="width:200px;" name="sourceincome' + rowCount + '" class="form-control sourceincome01" /></td>' +
'<td style="width:200px;"><button type="button" id="btnAdd" class="btn btn-xs btn-primary classAdd">Add More</button>' +
'<button type="button" id="btnDelete1" class="deleteContact btn btn btn-danger btn-xs">Remove</button></td>' +
'</tr>';
$('#maintable').append(contactdiv);
});
$(document).on("click", "#btnAdd2", function () {
var rowCount = $('.data-contact-person2').length + 1;
var contactdiv = '<tr class="data-contact-person2">' +
'<td><input type="text" style="width:200px;" name="spousename' + rowCount + '" class="form-control spousename01" /></td>' +
'<td><input type="text" style="width:200px;" name="spouseaddress' + rowCount + '" class="form-control spouseaddress01" /></td>' +
'<td><input type="text" style="width:200px;" name="spouseincome' + rowCount + '" class="form-control spouseincome01" /></td>' +
'<td><button type="button" id="btnAdd2" class="btn btn-xs btn-primary classAdd">Add More</button>' +
'<button type="button" id="btnDelete2" class="deleteContact btn btn btn-danger btn-xs">Add More</button></td>' +
'</tr>';
$('#maintable2').append(contactdiv);
});
$(document).on("click", ".deleteContact", function () {
$(this).closest("tr").remove();
});
function getAllEmpData() {
var data = [];
$('tr.data-contact-person').each(function () {
var sname = $(this).find('.sourcename01').val();
var saddress = $(this).find('.sourceaddress01').val();
var sincome = $(this).find('.sourceincome01').val();
var spname = $(this).find('.spousename01').val();
var spaddress = $(this).find('.spouseaddress01').val();
var spincome = $(this).find('.spouseincome01').val();
var alldata = {
'mySource': sname,
'mySAddress': saddress,
'mySIncome': sincome,
'mySpouse': spname,
'mySPAddress': spaddress,
'mySPIncome': spincome
}
data.push(alldata);
});
console.log(data);
return data;
}
$("#btnSubmit").click(function () {
var data = JSON.stringify(getAllEmpData());
$.ajax({
url: 'disclosures.aspx/SaveData',
type: 'POST',
dataType: 'json',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({ 'empdata': data }),
success: function () {
alert("Data Added Successfully");
},
error: function () {
alert("Error while inserting data");
}
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div class="container">
<h2>Forms</h2>
<table class="table" id="maintable">
<thead>
<tr>
<th>Name</th>
<th>Address</th>
<th>Income</th>
</tr>
</thead>
<tbody>
<tr class="data-contact-person">
<td>
<input type="text" style="width:200px;" name="sourcename" class="form-control sourcename01" /></td>
<td>
<input type="text" style="width:200px;" name="sourceaddress" class="form-control sourceaddress01" /></td>
<td>
<input type="text" style="width:200px;" name="sourceincome" class="form-control sourceincome01" /></td>
<td style="width:200px;">
<button type="button" id="btnAdd" class="btn btn-xs btn-primary classAdd">Add More</button>
</td>
</tr>
</tbody>
</table>
<table class="table" id="maintable2">
<thead>
<tr>
<th>Source </th>
<th>Address </th>
<th>Income</th>
</tr>
</thead>
<tbody>
<tr class="data-contact-person2">
<td>
<input type="text" style="width:200px;" name="spousename" class="form-control spousename01" /></td>
<td>
<input type="text" style="width:200px;" name="spouseaddress" class="form-control spouseaddress01" /></td>
<td>
<input type="text" style="width:200px;" name="spouseincome" class="form-control spouseincome01" /></td>
<td style="width:200px;">
<button type="button" id="btnAdd2" class="btn btn-xs btn-primary classAdd2">Add More</button>
</td>
</tr>
</tbody>
</table>
<button type="button" id="btnSubmit" class="btn btn-primary btn-md pull-right btn-sm">Submit</button>
</div>
</form>
</body>
</html>
'//CodeFile
Imports System.Collections.Generic
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.Linq
Imports System.Web
Imports System.Web.Services
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports Newtonsoft.Json
Partial Public Class disclosures
Inherits System.Web.UI.Page
Public Shared Constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Protected Sub Page_Load(sender As Object, e As EventArgs)
End Sub
<WebMethod()> _
Public Shared Function SaveData(empdata As String) As String
Dim serializedData = JsonConvert.DeserializeObject(Of List(Of Employee))(empdata)
Using con = New SqlConnection(Constr)
If con.State = ConnectionState.Closed Then
con.Open()
End If
For Each data As Employee In serializedData
Using cmd = New SqlCommand("INSERT INTO SourceDetails(sourcename, sourceaddress, sourceincome, createDate) VALUES(@sname, @saddress,@sincome,@CreatedDate)")
cmd.CommandType = CommandType.Text
cmd.Parameters.AddWithValue("@sname", data.mySpouse)
cmd.Parameters.AddWithValue("@saddress", data.mySAddress)
cmd.Parameters.AddWithValue("@sincome", data.mySIncome)
cmd.Parameters.AddWithValue("@CreatedDate", DateTime.Now)
cmd.Connection = con
cmd.ExecuteNonQuery()
End Using
Next
con.Close()
End Using
Return Nothing
End Function
End Class
Public Class Employee
Public Property mySpouse() As String
Get
Return m_mySpouse
End Get
Set(value As String)
m_mySpouse = value
End Set
End Property
Private m_mySpouse As String
Public Property mySAddress() As String
Get
Return m_mySAddress
End Get
Set(value As String)
m_mySAddress = value
End Set
End Property
Private m_mySAddress As String
Public Property mySIncome() As String
Get
Return m_mySIncome
End Get
Set(value As String)
m_mySIncome = value
End Set
End Property
Private m_mySIncome As String
Public Property CreatedDate() As DateTime
Get
Return m_CreatedDate
End Get
Set(value As DateTime)
m_CreatedDate = Value
End Set
End Property
Private m_CreatedDate As DateTime
End Class
modified 6-Mar-17 9:35am.
|
|
|
|
|
You fail to check the return value from your call to cmd.ExecuteNonQuery() , so you have no way of knowing whether that succeeded or not. In your ajax calls, where do the success or failure statuses come from, and what other status information is available?
|
|
|
|
|
Hi Richard,
Many thanks for attempting to help.
My experience with ajax call and JSON object WebMethods() tells me that you can't get to codebehind unless you get beyond the alert() message.
I could be wrong so far but to answer your question, I think that using
console.log(data); tells me what values are being passed to getAllEmpData and then to #btnsubmit control.
For instance, when I tried to use firebug to inspect the code, I got the following:
SCRIPT16389: Unspecified error.
[object Object],[object Object]
[{},{"mySource":"Martin Short","mySAddress":"1 Hollywood Way","mySIncome":"3401221"}]
This tells me that returning
[object Object],[object Object] is a problem somewhere with function because the correct information I entered from markup is captured and displayed as JSON objects below
[object Object],[object Object] .
I just don't know what is causing it.
Hope I am making sense.
|
|
|
|
|