Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 6th, 2004, 02:18 AM
Registered User
 
Join Date: Jul 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Adodb.stream File could not be opened.

Hi guys,
Have a problem with uploading files from asp to the server using the Stream object.
onSubmit this error prompts. It works fine on my local but when uploaded the source to server this error prompts. Error occurs on the line <stm.LoadFromFile "C:\Temp2\pic1.jpg">
Here the codes.

Set stm = Server.CreateObject("ADODB.Stream")
stm.Type = 1
stm.Open
stm.LoadFromFile ""&request("file")&""
stm.Close
Set stm = Nothing

Pls Help.
regards
issa rabba

 
Old July 6th, 2004, 03:30 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Issa,

You cannot access you local drives from the server, you will first need to upload the file.

The following article will enable you to do that:

http://www.pscode.com/vb/scripts/Sho...=7361&lngWId=4

HTH,

Chris

 
Old July 6th, 2004, 04:47 AM
Registered User
 
Join Date: Jul 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi man,

thnx for your replay, but i forget to tell u that i will save the file to SQLServer, not to localfile, my code is working perfict from my localserver but when I install the script at the server it give's me the error, can you help me?

this is my code

    var file = Request.QueryString("file");

    rs.Open;
    rs.AddNew;

    var imgStream=Server.CreateObject("Adodb.stream");
    imgStream.type= 1;
    imgStream.open;
    imgStream.loadfromfile(file);

    rs.fields("img").value = imgStream.read;

    rs.Update;
    rs.Close;
    rs = null;
    imgStream.Close;


Quote:
quote:Originally posted by ChrisScott
 Hi Issa,

You cannot access you local drives from the server, you will first need to upload the file.

The following article will enable you to do that:

http://www.pscode.com/vb/scripts/Sho...=7361&lngWId=4

HTH,

Chris

 
Old July 6th, 2004, 05:05 AM
Registered User
 
Join Date: Jul 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

and another thing, the example which you send to me is VB script, can you please send to me JavaScript Example if you know.

thnx
Regards

 
Old July 6th, 2004, 06:01 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Issa,

If you download the code from the link I posted, you will see there is a demo that saves the data to an access database, you should be able to get this to work with sql server no problem.

As far as doing it with JavaScript goes, AFAIK there is no equivalent to VBScript CharB method that is critical to the upload process, so you'll need to either use some VBScript or use a COM object of some sort.

I managed to get the demo to work with code *mainly* in JavaScript by replacing the ToDatabase.asp page with the following...

Code:

<script language="VbScript" runat="Server">
Call DoJs(New clsUpload)

Function GetChrB(pCharCode)
    GetChrB = ChrB(pCharCode)
End Function 
</script>

<script language="JavaScript" runat="Server">
function DoJs(pClsUpload){
    // Grab the file name
    var fileName = pClsUpload.Fields("File1").FileName;
    var conn = Server.CreateObject("ADODB.Connection");
    var rs = Server.CreateObject("ADODB.Recordset");

    conn.Open("DRIVER=Microsoft Access Driver (*.mdb);DBQ=" + Server.MapPath("Files.mdb"));
    //conn.Open("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("Files.mdb"));

    rs.Open("Files", conn, 3, 3);
    rs.AddNew();
    rs.Fields("FileName").Value = pClsUpload.Fields("File1").FileName;
    rs.Fields("FileSize").Value = pClsUpload.Fields("File1").Length;
    rs.Fields("ContentType").Value = pClsUpload.Fields("File1").ContentType;
    rs.Fields("BinaryData").AppendChunk(pClsUpload("File1").BLOB + GetChrB(0));
    rs.Update();
    rs.Close();

    rs.Open("SELECT Max(FileID) AS ID FROM Files", conn, 3, 3);
    var fileId = rs.Fields("ID").Value;
    rs.Close();

    rs = null;
    conn.Close()
    conn = null;
    pClsUpload = null;

    Response.Write("<a href=\"DataFile.asp?FileID=" + fileId + "\">" + fileName + "</a>");
}    
</script>
HTH,

Chris

 
Old July 6th, 2004, 06:22 AM
Registered User
 
Join Date: Jul 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks alot for your help, but it don't work it gives me this error
Error Type:

Microsoft VBScript runtime (0x800A0005)
Invalid procedure call or argument: 'MidB'
/upload2/clsUpload.asp, line 102

can you help please?

regards

 
Old July 6th, 2004, 06:25 AM
Registered User
 
Join Date: Jul 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank you very much it works

really thanks






Similar Threads
Thread Thread Starter Forum Replies Last Post
File stream Gridview to Excel yukijocelyn ASP.NET 2.0 Professional 0 October 1st, 2007 01:10 AM
reading a stream from all the lines of a file vaidyapragati ASP.NET 2.0 Basics 3 May 10th, 2007 02:33 AM
ADODB.Stream Open via URL (Unspecified error) blackadder_ba2 Classic ASP Components 2 December 7th, 2005 01:30 AM
ASP ADODB.Stream Open via URL (Unspecified error) blackadder_ba2 Javascript 0 December 5th, 2005 02:21 AM
Checking if a file is already opened before writin flyin General .NET 1 February 27th, 2004 11:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.