|
That stuff sounds too important to be using Excel for it?
YES, it can be done, but it depends on how the file is being created. If you're inserting data into an Excel sheet that already has the macros and formulas, then it's possible, and actually better to do directly in Excel than to use Office Interop and create the file with ASP then send it to the user. Just create an Excel sheet that downloads its data from the database.
http://office.microsoft.com/en-us/excel-help/connect-to-import-sql-server-data-HA010217956.aspx[^]
Using Office Interop to create the Excel sheet and send it back to the user doesn't have any security problems you can't get around. Users will have to confirm some dialog boxes, which they never read anyway. However, the Office Interop stuff falls into category 4 - it's hard to do to begin with, and very hard to maintain. I'll send you some of my Interop code if you want to see - it's explicit, ugly, verbose, hard-coded stuff. (now, that was a few years ago, so it might be better now, but I doubt it)
To test your security, you might want to just put a file up there that has the features you want, and give some users the link to it. Downloading it from IIS as a file should be almost the same as streaming it back from a page.
Still, this sounds like a horrible way to manage budgets! Teach these folks about accounting software and reporting tools and get them out of your hair!
|
|
|
|
|
Hi,
I need to create MS Excel file from DataTable in ASP.NET application. I don't need "SaveAs" dialog. Just create a file and save them to some folder.
I've searched the internet and found some examples how to do that by using Microsoft Excel Interop library. But, I can't use Excel Interop library. Is there any other way to do it?
Thank you in advance.
Goran
|
|
|
|
|
|
If you don't need special formatting or formulas then just drop the file as CSV. Excel will open CSV files with or without column names as the first row. Your question doesn't include any requirements that aren't met by a CSV file. And yes, I agree, using the Office Interop stuff is horrifying - I wrote an article about it years ago, and I still get questions on that article today. It's pretty tricky.
|
|
|
|
|
Yes. We can create CSV file instead of XLS. But, there's only one thing that could be a little bit undesired - wizard that opens CSV file. I'm not sure, but I think MS Excel cannot open CSV file directly without using wizard. Is that right?
|
|
|
|
|
Nope. Excel can open a CSV file directly.
|
|
|
|
|
Right, and any of those security dialogs that come up - the users don't even notice that stuff. Even if the conversion wizard does come up, the users probably won't care. They complete those tasks by rote - it's a bad habit really, but it's not a huge interruption to their day. Which is not to say you shouldn't worry about it - it's a legitimate concern, but it's not as big a problem as we sometimes think.
|
|
|
|
|
Hi guys,
I am building a report, in the report i should display 7 site name with check box, and if the report belongs to 1st site that check box should be checked, if the report belongs 2 sites it should check both 1st and 3rd
any help will be appreciated.
Thanks and regards
VISHWA
|
|
|
|
|
Hi,
Basically you are going to print your report. So why don't you create jpg for checked and unchecked display. if report belong to 1st site then display checked jpg in that one and otherwise default one. and for two sites you can change checked jpg for those options.
It will look similar like it is checkbox. I suggest this solution because i do not have idea about checkbox in report. sorry for that.
Thanks
-Amit Gajjar (MinterProject)
|
|
|
|
|
Hi Amit,
Thanks for the reply, I was also thought the same, but not having idea how to make jpg files should be display depends on the condition, so put a question on the form, will try the possible ways,
Thanks and regards
Vishwa
|
|
|
|
|
Your welcome
Thanks
-Amit Gajjar (MinterProject)
|
|
|
|
|
There is a physical html file and I need to traverse through all the html elements in an html file.
And the constraint is I can't use any third party components like HtmlAgilityPack or SuperStarHtml.
I think the best way is to preparing a XmlDocument from the html. But it is erroring out if the html contains any characters like .
Anyone having any idea to resolve this please share with me.
Thanks in advance.
|
|
|
|
|
HTML is not XML; you can't use an XML parser to load HTML.
Why can't you use a third-party component? Writing your own version of HtmlAgilityPack seems like a lot of work to satisfy a "Not Invented Here" philosophy.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I have developed a custom Comment Control using class library file
now i want to use the dll of this file in web application which is developing on MVC Framework
so what are the ways of adding and using this dll in this project
|
|
|
|
|
Are you having trouble with the normal ways? You know, adding the DLL directly as a reference, or adding your whole project and referencing the project?
|
|
|
|
|
I have added dll file in project reference, bin folder as well as bin_deployableAssemblies
now i want use this control in .cshtml file
how can i write syntax for use this control in this file
|
|
|
|
|
It would have been nice if you could have said that at the beginning. I haven't ever done that myself, but ten seconds on Google did find this article, which looks to be what you're trying to do.
Custom Controls in MVC[^]
WHY were you not able to find that on Google? Or did you read it and need help with it?
|
|
|
|
|
i had serach on google but i was not found anything that what i want
i hav done custom control(generic) in asp.net
and i want implement it in web application which has in MVC framework.
|
|
|
|
|
The article I posted should get you there. It is about MVC, like it says. I don't think it's standard procedure to use server controls in MVC, but it's possible to do if you want.
|
|
|
|
|
OK, I'm at my wit's end with this sucker! I basically think I have two options, and both options are doing something screwed up and I can't explain why, but would really just rather have it stop! I'm trying to integrate a KendoUI Grid control, and an ASMX page method. I got the "Read" method to work great - it did take some work to get the JSON running back and forth properly, but it works really nicely. Now, I'm trying to do the "Update" and "Create" methods. The problem is my grid isn't sending back the proper data format. It's sending the right data, but the encoding is screwed up in many different ways depending on how I do it.
Here's my JQuery code at the moment...
function getJson(input) {
var k = JSON.stringify(input);
return k;
}
$(document).ready(function () {
$("#PeopleGrid").kendoGrid({
columns: ["LastName", "FirstName", "Phone"],
dataSource: {
transport: {
read: {
type: "POST",
url: "TestKendoGrid.aspx/Read",
contentType: "application/json; charset=utf-8",
dataType: "json"
},
create: {
type: "POST",
url: "TestKendoGrid.aspx/Create",
contentType: "application/json; charset=utf-8",
dataType: "json"
},
update: {
type: "POST",
url: "TestKendoGrid.aspx/Update",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: function (x) { return getJson(x); }
}
},
schema: {
data: "d",
columns: ["ID", "LastName", "FirstName", "Phone"],
model: {
id: "ID",
fields: {
LastName: {
editable: true,
nullable: false
},
FirstName: {
editable: true,
nullable: false
},
Phone: {
editable: true,
nullable: false
}
}
}
},
batch: false
},
editable: {
update: true,
create: true,
destroy: false
},
toolbar: ["create", "save", "cancel"]
})
});
The little function at the top is just so I can see the values in the debugger. With the current code, "input" is the actual object I'm trying to send back and "k" actually IS the exact JSON string I want to POST back to my server. Problem is, when I look at what was actually sent, it's funky as hell! This is what the request looks like...
POST http://localhost:54346/TestKendoGrid.aspx/Update HTTP/1.1
Host: localhost:54346
Connection: keep-alive
Content-Length: 1930
Accept: application/json, text/javascript, */*; q=0.01
Origin: http://localhost:54346
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31
Content-Type: application/json; charset=UTF-8
Referer: http://localhost:54346/TestKendoGrid.aspx
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: ASP.NET_SessionId=dkmbybyaz0bitvat2wbdueti
0=%7B&1=%22&2=_&3=_&4=t&5=y&6=p&7=e&8=%22&9=%3A&10=%22&11=T&12=e&13=s
&14=t&15=W&16=e&17=b&18=S&19=i&20=t&21=e&22=.&23=P&24=e&25=r&26=s&27=o
&28=n&29=%22&30=%2C&31=%22&32=I&33=D&34=%22&35=%3A&36=5&37=%2C&38=%22&39=L
&40=a&41=s&42=t&43=N&44=a&45=m&46=e&47=%22&48=%3A&49=%22&50=A&51=d&52=a
&53=m&54=s&55=o&56=n&57=%22&58=%2C&59=%22&60=F&61=i&62=r&63=s&64=t&65=N
&66=a&67=m&68=e&69=%22&70=%3A&71=%22&72=D&73=a&74=n&75=i&76=e&77=l&78=l
&79=e&80=%22&81=%2C&82=%22&83=P&84=h&85=o&86=n&87=e&88=%22&89=%3A&90=%22
&91=3&92=0&93=3&94=-&95=5&96=2&97=3&98=-&99=8&100=7&101=1&102=9&103=%22
&104=%2C&105=%22&106=E&107=n&108=t&109=i
&110=t&111=y&112=S&113=t&114=a&115=t&116=e&117=%22&118=%3A&119=2&120=%2C
&121=%22&122=E&123=n&124=t&125=i&126=t&127=y&128=K&129=e&130=y&131=%22&132=%3A
&133=%7B&134=%22&135=E&136=n&137=t&138=i&139=t&140=y&141=S&142=e&143=t&144=N
&145=a&146=m&147=e&148=%22&149=%3A&150=%22&151=P&152=e&153=o&154=p&155=l
&156=e&157=%22&158=%2C&159=%22&160=E&161=n&162=t&163=i&164=t&165=y&166=C
&167=o&168=n&169=t&170=a&171=i&172=n&173=e&174=r&175=N&176=a&177=m&178=e
&179=%22&180=%3A&181=%22&182=S&183=a&184=n&185=d&186=b&187=o&188=x&189=E&190=n
&191=t&192=i&193=t&194=i&195=e&196=s&197=%22&198=%2C&199=%22&200=E&201=n&202=t
&203=i&204=t&205=y&206=K&207=e&208=y&209=V&210=a&211=l&212=u&213=e&214=s
&215=%22&216=%3A&217=%5B&218=%7B&219=%22&220=K&221=e&222=y&223=%22&224=%3A&225=%22
&226=I&227=D&228=%22&229=%2C&230=%22&231=V&232=a&233=l&234=u&235=e&236=%22
&237=%3A&238=5&239=%7D&240=%5D&241=%2C&242=%22&243=I&244=s&245=T&246=e&247=m&248=p
&249=o&250=r&251=a&252=r&253=y&254=%22&255=%3A&256=f&257=a&258=l&259=s&260=e
&261=%7D&262=%7D&__type=TestWebSite.Person&ID=5&LastName=Adamson&FirstName=Danielle&Phone=303-555-1212&EntityState=2&EntityKey%5BEntitySetName%5D=People&EntityKey%5BEntityContainerName%5D=SandboxEntities
&EntityKey%5BEntityKeyValues%5D%5B0%5D%5BKey%5D=ID&EntityKey%5BEntityKeyValues%5D%5B0%5D%5BValue%5D=5&EntityKey%5BIsTemporary%5D=false
LOL, wut?! It's encoding each character as if it's a separate parameter! What in the hell?!
If I don't "stringify" it posts the data as URL-encoded, like this:
POST http://localhost:54346/TestKendoGrid.aspx/Update HTTP/1.1
Host: localhost:54346
Connection: keep-alive
Content-Length: 320
Accept: application/json, text/javascript, */*; q=0.01
Origin: http://localhost:54346
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31
Content-Type: application/json; charset=UTF-8
Referer: http://localhost:54346/TestKendoGrid.aspx
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: ASP.NET_SessionId=dkmbybyaz0bitvat2wbdueti
__type=TestWebSite.Person&ID=18&LastName=Russell&FirstName=Graham&Phone=303-555-5000&EntityState=2&EntityKey%5BEntitySetName%5D=People&EntityKey%5BEntityContainerName%5D=SandboxEntities
&EntityKey%5BEntityKeyValues%5D%5B0%5D%5BKey%5D=ID&EntityKey%5BEntityKeyValues%5D%5B0%5D%5BValue%5D=18&EntityKey%5BIsTemporary%5D=false
And of course, ASP.Net responds to that with a 500 error of "Invalid JSON Primitive" which basically means it choked, according to http://encosia.com/asmx-scriptservice-mistake-invalid-json-primitive/[^]
So, I'm trying to follow the advice in the article, but that's causing the really weird request in the first snippet. So, I'm not sure what to do!
It should be posting this (the value of "k" in the little function):
{"__type":"TestWebSite.Person","ID":5,"LastName":"Adamson","FirstName":"Danielle","Phone":"303-555-1212","EntityState":2,"EntityKey":{"EntitySetName":"People","EntityContainerName":"SandboxEntities","EntityKeyValues":[{"Key":"ID","Value":5}],"IsTemporary":false}}
My WebMethod on the receiving side is here - the Read method works great, but the other two haven't even seen a proper request so I'm not sure if they are correct yet.
[WebMethod]
public static List<Person> Read() {
using (SandboxEntities entity = new SandboxEntities()) {
var q = from p in entity.People
select p;
return q.ToList<Person>();
}
}
[WebMethod]
public static void Create(Person pIn) {
using (SandboxEntities e = new SandboxEntities()) {
e.AddToPeople(pIn);
e.SaveChanges();
}
}
[WebMethod]
public static void Update(Person pIn) {
using (SandboxEntities e = new SandboxEntities()) {
Person pUpdate = (Person)(from p in e.People where p.ID == pIn.ID select p).First();
pUpdate.Phone = pIn.Phone;
pUpdate.FirstName = pIn.FirstName;
pUpdate.LastName = pIn.LastName;
e.SaveChanges();
}
}
I've dug myself a big hole here, please help me get out! TIA
modified 1-Apr-13 19:19pm.
|
|
|
|
|
|
Thanks! I did get it figured out. Something to do with the ParameterMap function. I added a basic stringify into that, and now it sends back the proper JSON in the POST request.
However, now I'm getting some kind of type conversion problem. The incoming object IS being parsed correctly into a Person object, but then the framework is trying to convert it into a Dictionary object, which fails and throws an exception and a 500 back to the browser. I have no additional information than that, so it's a pretty big mystery at the moment.
I think this question is maybe too advanced for this forum. I know there's smart people here like you and me, and I thought this question was interesting enough to attract those folks, but I'm stumped so maybe everybody else is too? If you looked at this question and tried to solve it, please let me know what you found! We might work it out together.
This is the Javascript right now - this sends the proper JSON back to the server (and the server even deserializes it correctly to a Person object, then it chokes trying to do something unnecessary).
$(document).ready(function () {
$("#PeopleGrid").kendoGrid({
columns: ["LastName", "FirstName", "Phone"],
dataSource: {
transport: {
read: {
type: "POST",
url: "TestKendoGrid.aspx/Read",
contentType: "application/json; charset=utf-8",
dataType: "json"
},
create: {
type: "POST",
url: "TestKendoGrid.aspx/Create",
contentType: "application/json; charset=utf-8",
dataType: "json"
},
update: {
type: "POST",
url: "TestKendoGrid.aspx/Update",
contentType: "application/json; charset=utf-8",
dataType: "json"
},
parameterMap: function (data, type) {
return kendo.stringify(data);
}
},
schema: {
data: "d",
columns: ["ID", "LastName", "FirstName", "Phone"],
model: {
id: "ID",
fields: {
LastName: {
editable: true,
nullable: false
},
FirstName: {
editable: true,
nullable: false
},
Phone: {
editable: true,
nullable: false
}
}
}
},
batch: false
},
editable: {
update: true,
create: true,
destroy: false
},
toolbar: ["create", "save", "cancel"]
})
});
|
|
|
|
|
|
It's failing on the server side, but before it gets to my function. It's failing somewhere in the .Net Framework code, because it's trying to turn the Person object into a Dictionary, which is not a conversion that can be done. What I don't understand is why it's trying to do that, when it has a Person object it could pass directly to my function. Something isn't right in the wiring and I don't know what. I'll take a look at the article you posted and see what it's about, but I think I've read it before.
|
|
|
|
|
|