2

Closed

file upload issues

description

"... created a couple of forms using Survey that included the file upload answer type. The problem I am running into is that once a file is uploaded and submitted, the same file keeps showing in the form."

Severall issues were identified:
- FileManager.aspx: delete button does not work; download link does not work
- File upload answer object: list of uploaded files does show up on surveyform for all visitors

Closed Mar 25 at 6:59 PM by
Fixed in SP v.2.0 Stable

comments

fwsmaster wrote Feb 21 at 8:10 PM

Issues have been solved in SP v. 2.0.

jackielhong wrote Jan 16 at 2:11 AM

db file

jackielhong wrote Jan 16 at 2:10 AM

Another File

jackielhong wrote Jan 16 at 2:06 AM

Another File:

jackielhong wrote Jan 16 at 2:05 AM

Another File

jackielhong wrote Jan 16 at 2:01 AM

More Files

jackielhong wrote Jan 16 at 1:57 AM

Latest Files Attached

jackielhong wrote Jan 16 at 1:52 AM

Please review latest changes for File Upload issues. I have completed my own testing of the issues identified.

Basically, the changes involve auto generating the GroupGuid by calling an existing method, GenerateResumeUID, and adding the UserId to the vts_tbFile. Setting the GroupGuid is necessary since it is used as one of the primary key lookup for the File Upload. Adding the UserId is needed to allow the display of files uploaded for the loggin user as the current code pulls in all files uploaded per survey in vts_spFileValidatedGetAll.



*****DB methods modified in Survey123_NewDBInstall from Survey 1.2.3 tag:
1. Add UserId to vts_tbFile
2. vts_spFileAddNew
-add UserId
-remove records in vts_tbVoter and vts_tbVoterAnswers with same GroupGuid. This happens for
multiple uploads.
3. vts_spFileValidatedGetAll
-add UserId to Select criteria
4. vts_FileDelet
-ensure records in vts_tbVoter and vts_tbVoterAnswers are removed when files removed in
vts_tbFile table

Code Files Modified in Survey 1.2.3 tag"
1. AnswerUploadItem.cs
-modify UploadButton_Click add pass in UserId
-Setup GroupGuid by calling GenerateResumeUID of lenght 40 to create unique Id. Multiple
uploads will have same Id as GroupGuid is stored in ViewState which retains the value
-modify CreateChildControl not to call GenerateFileList so uploaded Files not displayed in
FormBuilder
2. FileManager.cs
-DeleteFilesButton_Click modified to access Cell[7] instead of Cell[1] for GroupGuid to correct
problem with Delete in FileManager function
-ValidatedFilesDataGrid_ItemCommand (called when download is clicked) to access Cell[7] instead
of Cell[1] for GroupGuid to correct problem with Download in FileManager function
-ExportFilesButton_Click modified to pass UserId in call to ExportAnswerFilesToDirectory
3. Answer.cs in Votations.NSurvey.SQLServerDAL
-GetValidatedFileAnswers modified take UserId
-StoreAnswerFile modified to take UserId
-
4. Answer.cs in Votation.NSurvey.Data.Access
-GetValidatedFileAnswers modified to also take UserId as input
5. Answer.cs in Votation.NSurvey.BusinessRules
-ExportAnswerFilesToDirectory modified to take UserId as input
-StoreAnswerFile modified to take UserId as input
6. IAnswer.cs in Votation.NSurvey.IDAL
-GetValidatedFileAnswers pass in UserId
-StoreAnswerFile pass UserId

jackielhong wrote Oct 18 2011 at 7:10 AM

Hi ljesquives,

Thank you for your comments. I think we agree that the GroupGuid does nothing for the lookup for the uploaded files or perhaps we don't know the intented use of it. Your suggestion to replace the questionNumber is good and passing the SurveyId is valid, but wouldn't all users of the same survey have the same surveyId and questionNumber ? That is why I suggest replace or add to GroupId the voterId as I think it is unique per question and per user of a survey. Somehow, we would need to tie the files to user for the 'results reports'. Not sure if the current table strcture allows for this or we need to add userId to one of the voters table.

Also, I see that the uploaded data is being saved to the vts_tbFile table each time a a 'uploaded' is done. If you notice for the other answer types, the anwer is not saved to the db till 'submit' is done. Rather the data is stored in the the viewstate var, voterAnswers and assigned a temp voterId. So, I think that changes are needed in AnswerUploadItem.cs to not save the data to vts_tbFile at that point when upload is clicked. Instead we should store all the file data to voterAnswers view state var. When submit to db is done, then a change is also needed to that function to store all file data to vts_tbFile. What do you think ?

ljesquives wrote Oct 16 2011 at 6:11 AM

Hi Jackie, reviewing this bug I have another bug. If you create 2 questions with upload file extender answers and if you go to asp.net code and upload a file in just one question, the same file will be displayed on 2 questions. Review the attached file.

In order to help a little bit, this are some solutions proposed (hope it helps):
- Create a column on named SurveyID on table "vts_tbFile"
- Modify the sp "vts_spFileAddNew" and add a new parameter "@SurveyID"
- On AnswerUploadItem.uploadButton_Click event you must send the SurveyID in order to save the person survey and reference the uploaded file with the survey.
- On AnswerUploadItem.uploadButton_Click event you must send the questionID to the sp using the "@GroupGuid" parameter you have (the best practice is change parameter, column, properties, etc named "GroupGuid" to "QuestionNumber" in order to name the column with the value saved).

At this momment you have the uploadbutton saving the file correctly and related to the survey and question and this will fix the problem you have on Form Builder.

But the changes applied to the sp and classes will destabilize queries and survey results, so you need make changes and check everything is working again.

jackielhong wrote Sep 1 2011 at 6:30 AM

Below are my proposed solutions to the errors identified in this issue. As these are just proposed solutions, not all details may have been thought out or included. I look forward to any feedback anyone would like to offer. Thank you.

1. Files uploaded through the survey form by one survey taker are shown to all other survey takers in Asp.net code and "results reports" of "Filemanager" . ( I suspect this is the same issue in the Voters Result page)
--I think the main problem is that the GroupGuid is used as the main key lookup to display the files uploaded, but the GroupGuid is often not set and it is null. The only way I know to set the GroupGuid (by looking at the code) is to enable the defaultText in form. But as noticed, even when the GroupGuid is set to some value, it still doesn't resolve this problem as there is no way to trace the files uploaded by the user currently. So, I suggest creating a new colum, voterId, in the vts_tbfile table to link it to the vts_tbVoter table. The changes would be to rework the
vts_spFileValidateGetAll procedure to also take as input the userId and reference the voterId field to join the vts_tbFile to vts_tbVoter table and select records per UserId. And modify all existing interfaces (such as GenerateFileList in AnswerUploadItem.cs) that use GroupGuid to replace or also use the voterId.

2. Same uploaded file is displayed in "results reports" – "File manager" for all different voterIds
--This is because a new record is created in the vts_tbVoter and vts_tbVoterAnswers tables each time a 'submit' is clicked in the Aspnet.code even if there is no change to the file uploaded, no file uploaded, or if the file has been deleted. Also if the file is deleted in the Asp.net code, then
the records in the vts_tbVoter and vts_tbVoterAnswers tables should be removed. I don't think this is currently being done. As a result, if user
uploads again, the file will displayed for that voterId of the deleted file. This would be a change to SurveyBox.cs in method SubmitAnswersToDb to check if the answer type is upload. If new upload only for answer, then create new records in vts_tbVoter and vts_tbVoterAnswers table.

3. uploaded files are shown on the survey form throught the Form builder
--This is due to code calling the same method, CreateChildControls, in AnswerUploadItem.cs for the formBuilder and Asp.net code. CreateChildControls always calls GenerateFileList to display the files uploaded. I think that a check is needed to distinguish the calls. When
called from formBuilder, this._uploadButton.Enabled is false and true when called from Aspnet.code. So, this can be used to not call GenerateFileList from the formBuilder when this._uploadButton.Enabled is false.

4. FileManager.aspx: delete button does not work; download link does not work
--In DeleteFilesButton_Click method, the wrong cell index, 1, is being passed to DeleteAnswerFile which is expecting the GroupGuid (in cell 7).
If fake a value to GroupGuid, then the record gets deleted. Again, I don't know how to set the GroupGuid without setting it in DefaultText of the
form. I would suggest my solution in error #1 to add the new field, voterId, in the vts_tbFile table.
For the download, it is a similar problem. In ValidatedFilesDataGrid_ItemCommand, it calls SendFile with the wrong cell index of GroupGuid. It
should be index 7 instead of 1. If fake a value to GroupGuid, then the record gets downloaded. Again, I don't know how to set the GroupGuid
without setting it in DefaultText of the form. I would suggest my solution in error #1 to add the new field, voterId, in the vts_tbFile table.

jackielhong wrote Aug 23 2011 at 12:56 AM

I think I did not fully understand all the problems associated with this issue and thus the solution was incorrect. The PDF file is very helpful and I will try to go through it and see if I can propose any solution. Thank you.

fwsmaster wrote Aug 22 2011 at 5:05 PM

Hi Jackie, no need to apologize, it's a really complicated issue and your efforts are appreciated. You can share suggestion for solutions but please make sure you have tested them yourself before uploading or just present them as a proposed solution you need advise on or want to discuss. The pfd error file is the result of a quick analyses from a users point of view. To really determine the cause of the error you have to study the source code really well (both database and application).

One additional error that was descoverd is that when uploading files the answers and voteranswers tables are updated. Next when you submit the form at the end of the survey another update takes place to those tables. This is one of the causes of having double entries shown in the filemanager overview of uploaded files.

Meanwhile any assistance on this issue from other teammembers is highly appreciated.
Kind regards
Fwsmaster

jackielhong wrote Aug 22 2011 at 9:09 AM

Sorry that my solution did not fix the problem. I did not see the file with the steps of the errors. I will look at this file.

fwsmaster wrote Aug 20 2011 at 2:51 PM

Unfortunately the proposed solution does not fix the problems. You have managed to set the Groupguid by adding a Default Text field to the Answer Item options but this has no effect on the errors that need to be corrected for the Extended Upload FTP answeritem to work correctly. Please check the enclosed document for a complete description of all errors that need to be corrected related to the Extended Upload FTP answeritem error. If you can have another try at analysing the issues or if any other members can help out it would be appreciated. Please test carefully before you upload any possible solutions.

jackielhong wrote Aug 20 2011 at 2:14 AM

Here is the code in AnswerUploadItem.cs that sets the value of groupGuid. Since it requires the DefaultText, that is why I enabled the field in the AnswerOptionControl.ascx.cs. When the user enters the text in the DefaultText, it sets the groupGuid in vts_tbFile table. Do you know the know the reasoning behind this for uploading the answer ?

public string GroupGuid
{
get
{
if (this.ViewState["GroupGuid"] == null)
{
object obj2 = string.Empty;
this.ViewState["GroupGuid"] = (this.DefaultText == null) ? obj2 : this.DefaultText;
}
return this.ViewState["GroupGuid"].ToString();
}
set
{
this.ViewState["GroupGuid"] = value;
}
}

jackielhong wrote Aug 20 2011 at 1:50 AM

Did you add some text to the 'default' text in the upload answer form ? Seems this is the way I found that the groupId gets populated.

fwsmaster wrote Aug 17 2011 at 5:52 PM

Could it be you uploaded the old version of the AnswerOptionControl file? The groupguid still does not seem to get filled in vts_tbfile.

jackielhong wrote Aug 17 2011 at 2:05 AM

Here is the attachment for FileManager.aspx.cs

jackielhong wrote Aug 17 2011 at 2:02 AM

I have attached the following two files for the fixes to this issue. These changes are to the source code from Survey 1.2.3 tag.

1. AnswerOptionControl.ascx.cs - List of uploaded files should now display only the ones for the selected survey of the user. However, I see that the same uploaded files would show up for all the different voter ids. Is this how it should work or should the uploaded file only show once ?

2. FileManager.aspx.cs - Should fix the problems with the delete and download.

fwsmaster wrote Aug 8 2011 at 5:19 PM

Hi Jackie, It certainly looks like you're working in the right direction. Looking forward to the results and the testing. If any one feels like assisting please let us know through the comments.

Kind regards
Fwsmaster

jackielhong wrote Aug 8 2011 at 2:20 PM

Seems that as an admin, a user can see all the surveys in the system. If non admin, then he only sees the survey created by him. So, this is working as is.

I will continue my testing on the defaultText fix.

jackielhong wrote Aug 8 2011 at 1:00 PM

I think I have fixed part of this problem by making sure that the defaultText text box is enabled for the user when he selects the file upload answer type. This change was in AnwerOptionControl.ascx.cs. When the defaultText is set, it sets up the groupId in the vts_tbFile. This groupId had always been null prior and thus leading to part of the reason the same uploaded file keeps showing up for all the surveys. I will test this fix further.

Also, seems that currently, a user can select any survey (even for another user) he wants to display the files uploaded from the drop down list. I am looking to see if this is just a privilege as an admin or something that needs to be fixed.

jackielhong wrote Jun 17 2011 at 12:05 PM

In the process of trying to find a solution to this problem. But will be on vacation till mid July and will continue to work on it when return.