Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Upload Problem

Status
Not open for further replies.

f0z

Programmer
Jan 10, 2003
48
0
0
US
I'm sure this has been covered before so I'm hoping that some one has a quick and easy answer ;)

Basically I have a web application that lets a user publish a document to sharepoint. It's a fairly basic application, user just fills in a few fields chooses the file thats to be published via a <input type="file"... />.

Testing locally (file to be uploaded and webserver on the same machine) everything works fine, but when I upload the app to our live server it crashes with a System.Runtime.InteropServices.COMException: File could not be opened error. Of course the main difference here is that the file and webserver are on different machines.

Obviously if the user browses to a file saved in their c:\docs folder, for example, when this gets passed to application, the app is going to look for this folder on the server and this would generate an error.

I've tried using a \\servername\sharename\doc.doc but this still doesnt work.

All permissions seem to be set fine, the everyone account has been given full access to the share and still no joy.

Any help is greatly appreciated,

f0z
 
it's not true that the server will look for the directory that the user specified. this is done client side and the file is being sent to server. the server must know where to save the file and must have access to the directory where the file is to be saved.

this means that you should check to see if ASPNET has access to write files in the directory where you choose to save the file and to the temporary directory (this is correct by default)

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
cheers for that - gave the aspnet account the correct access levels to the folder but the problem still persists because I'm not able to open the file.

As a test i've created an identical folder on the server c:\docs with the samefile located inside it - and it works fine then.

Would that not suggest that it's looking to the local machine?
 
I guess I could do an intermediary standard upload. And the use PKMCDO to take the new file from where ever the System.Web.UI.HtmlControls.HtmlInputFile.PostedFile.SaveAs saved it to.
 
this means that you save the file in c:\docs and that it needs permission to do that but file upload does not relate the server with the directory structure of the client in any way. I believe you can get info about where the file is from (I'm not sure though) but the file once sent to the server can be saved in any directory the application wants to as long as it has the necessary permissions.

if this is your application, try debugging it and see what folder does it try to save the file to.

also posting some code will help us understand your problem better.

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
Here's the code:

Code:
PKMCDO.KnowledgeVersion docKnowVer = new PKMCDO.KnowledgeVersion();

PKMCDO._Stream docStream;
PKMCDO.KnowledgeDocument KnowDoc = new PKMCDO.KnowledgeDocument();

docStream = (PKMCDO._Stream)KnowDoc.OpenStream( (object) System.Type.Missing, PKMCDO.EnumKnowledge_StreamOpenSourceType.pkmOpenStreamUnspecified, null, PKMCDO.ConnectModeEnum.adModeUnknown,null,null);

docStream.SetEOS();
docStream.LoadFromFile(tbFile.Value.ToString());
docStream.Flush();

KnowDoc.Title = tbTitle.Text.ToString();
KnowDoc.Author = tbIssuedBy.Text.ToString();
KnowDoc.Description = tbDesc.Text.ToString();
KnowDoc.Categories = new object[] {":Category"};

KnowDoc.DataSource.SaveTo("[URL unfurl="true"]http://servername/workspace/Documents/Category/"+strFileName,[/URL] null, PKMCDO.ConnectModeEnum.adModeReadWrite, PKMCDO.RecordCreateOptionsEnum.adCreateOverwrite, PKMCDO.RecordOpenOptionsEnum.adDelayFetchStream, @"domain\username", "password");

docKnowVer.Checkin(KnowDoc,0,"Document Check-In");
docKnowVer.Publish(KnowDoc,0);

Saving the file doesnt seem to be the problem its actually getting the file opened in the docStream.LoadFromFile(tbFile.Value.ToString()) line that seems to be the problem.
 
I've added this piece of code in there now:

Code:
string path = @"C:\temp\";
string strUrl = path + strFileName;
tbFile.PostedFile.SaveAs(strUrl); // this creates a local copy

and amended the line
Code:
// before
docStream.LoadFromFile(tbFile.Value.ToString());
// after
docStream.LoadFromFile(strUrl);

Now this works but seems like a little bit of overkill.

Uploading a document to the temp folder and then using the KnowDoc.DataSource.SaveTo to publish from a local folder.

Maybe it's that the KnowDoc.DataSource.SaveTo needs the document to be on the local machine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top